Skip to content

Triggers

Jaroslav Surala edited this page Jan 12, 2020 · 2 revisions

Triggers

FlexGrid support runtime changing of some properties.

Manual refresh of current page

You can manually invoke refresh of current page.

<button class="btn btn-primary" @onclick="@ReloadCurrentPage">Reload data</button>

async Task ReloadCurrentPage()
{
  await dataAdapter.ReloadCurrentPage();
}

Change DataAdapter

You can change your data adapter for Grid while runtime.

@inject LazyLoadedTableDataAdapter<WeatherForecast> forecastAdapter

<GridView DataAdapter="@dataAdapter"
          LazyLoadingOptions="@options"
          PageSize="10"
          SaveOperationFinished="@ItemSavedOperationFinished"
          DeleteOperationFinished="@ItemDeletedOperationFinished"
          NewItemCreated="@ItemCreated">
</GridView>
<button class="btn btn-primary" @onclick="@ChangeDataAdapter">Change data adapter</button>
@code{

    ITableDataAdapter dataAdapter;
    protected override void OnInitialized()
    {
        base.OnInitialized();
        dataAdapter = forecastAdapter;
    }
    async Task ChangeDataAdapter()
    {
        var forecast = await Http.GetJsonAsync<WeatherForecast[]>("api/SampleData/WeatherForecastsSimple");
        dataAdapter = new CollectionTableDataAdapter<WeatherForecast>(forecast);
    }
}

Change page size

<GridView DataAdapter="@dataAdapter" PageSize="@pageSize"></GridView>
<button class="btn btn-primary" @onclick="@SetPageSize">Change page size</button>

async Task SetPageSize()
{
  pageSize++;
}

Change LazyLoadingOptions

<GridView DataAdapter="@dataAdapter"
          LazyLoadingOptions="@options"
          PageSize="10">
</GridView>
<button class="btn btn-primary" @onclick="@ChangeOptions">Change options</button>

void ChangeOptions()
{
    options = new LazyLoadingOptions()
    {
        DataUri = "api/SampleData/WeatherForecasts",
        PutDataUri = "api/SampleData/UpdateWeatherForecast",
        DeleteUri = "api/SampleData/Delete/{Id}"
    };

    options.RequestParams.Add("test", "value");
}