Mewriick / Blazor.FlexGrid

GridView component for Blazor
MIT License
199 stars 35 forks source link

Trigger Reload to Fetch Data with Lazy #62

Closed aherrick closed 4 years ago

aherrick commented 5 years ago

I have code like this. When I click Apply Filters I want the grid to fire back to the API endpoint with the added Request Parm. How do I do this?

<form class="form-inline">
    <div class="form-group mb-2">
        <label for="temp">Temp</label>
        <input type="text" class="form-control" @bind="@Name" />
    </div>

    <button type="button" onclick="@ApplyFilters" class="btn btn-primary mb-2">Apply Filters</button>
</form>

<GridView DataAdapter="@forecastAdapter" LazyLoadingOptions="@lazyLoadingOptions" PageSize="10"></GridView>

@code {

    LazyLoadingOptions lazyLoadingOptions { get; set; }
    private string Name { get; set; };

    protected override async Task OnInitAsync()
    {
        lazyLoadingOptions = new LazyLoadingOptions() { DataUri = "https://localhost:44366/demo/WeatherForecasts" };
    }

    private void ApplyFilters()
    {
        lazyLoadingOptions.RequestParams.Add("Search", "SearchString");
    }
}
Mewriick commented 5 years ago

Hello @aherrick

waht you want to accomplish by this scenario? If you want to filter by this value you can use filter API which FlexGrid provide.

aherrick commented 5 years ago

Hi @Mewriick I don't want/need to use the built in table filtering. For example I may have a field that isn't showing or used in the grid that I simply want to filter by.

I'm just simply trying to force a callback.

Mewriick commented 5 years ago

Ok, unfortunately now there is not such a feature to force call API when you click your button.

Mewriick commented 5 years ago

Only solution now maybe is

    private void ApplyFilters()
    {
        lazyLoadingOptions = lazyLoadingOptions.RequestParams.Add("Search", "SearchString");
    }

which should invoke OnSetParameterAsync method in FlexGrid and ther is call to go to first page which invoke API call.

aherrick commented 5 years ago

Resetting lazyLoadingOptions in this way isn't valid.

7-28-2019 9-38-32 AM

Mewriick commented 5 years ago

Yeah, I see it now. So basically you can do this:

private void ApplyFilters()
{
    lazyLoadingOptions = new LazyLoadingOptions()
        { 
             DataUri = lazyLoadingOptions .DataUri,
             PutDataUri = lazyLoadingOptions.PutDataUri,
             DeleteUri = lazyLoadingOptions.DeleteUri 
        }.RequestParams.Add("Search", "SearchString");
}
aherrick commented 5 years ago

Hmm so I'm trying even this and still isn't forcing a server call:

    private void ApplyFilters()
    {
        lazyLoadingOptions = new LazyLoadingOptions()
        {
            DataUri = lazyLoadingOptions.DataUri
        };
    }
Mewriick commented 5 years ago

The OnParametersSet and OnParametersSetAsync methods are called when a component is first initialised and each time new or updated parameters are received from the parent in the render tree.

your scenario is that object is still same

aherrick commented 5 years ago

I've tried below which doesn't work.

    lazyLoadingOptions = new LazyLoadingOptions()
        {
            DataUri = lazyLoadingOptions.DataUri
        };
        lazyLoadingOptions.RequestParams.Add("test", "test");

While this throws errors:


        lazyLoadingOptions = new LazyLoadingOptions()
        {
            DataUri = lazyLoadingOptions.DataUri
        }.RequestParams.Add("test", "test");

Is there a different way to Initialize the object and set the request parameters at the same time?

Mewriick commented 5 years ago

I think you can do this

var secondLazyLoadingOptions = ..... ;
lazyLoadingOptions  = secondLazyLoadingOptions ;
aherrick commented 5 years ago

Unfortunately that doesn't work either:

    private void ApplyFilters()
    {
        var secondLazyLoadingOptions = new LazyLoadingOptions()
        {
            DataUri = lazyLoadingOptions.DataUri,
        };
        secondLazyLoadingOptions.RequestParams.Add("test", "test");

        lazyLoadingOptions = secondLazyLoadingOptions;
    }

Not sure how you fill the RequestParams in initialization as it's a getonly property.

Mewriick commented 5 years ago

Ok I think that OnParametersSetAsync of FlexGrid is called but some conditions are false and method which call API is not called. This is not supported scenarion and this is only hack so this can not be done now

aherrick commented 5 years ago

Ok, unfortunately it's a deal breaker for me then to use the Grid.

Mewriick commented 5 years ago

Yeah Ok, also you can suggest how to solve this and use pull request.

Mewriick commented 4 years ago

@aherrick

Version 0.11.0 contains new feature which you can use for refreshing grid view. See the wiki