7 Answers, 1 is accepted
Hi Cameron,
Indeed, that's the most straightforward way.
An alternative is to get the current grid state (see the GridRef.GetState() method), and create a new DataSourceRequest object with the current filters, then use the .ToDataSourceResult() extension method of ours with that request - this would let you perform the same operation on the data as the grid does internally so you can fetch the same data. Ultimately, it's almost the same as using the OnRead event. If you already have all the data in the view model, the .ToDataSourceResult() method can let you do that filtering for the grid too, pretty easily.
Regards,
Marin Bratanov
Progress Telerik

Hi Cameron,
Indeed, that's the most straightforward way.
An alternative is to get the current grid state (see the GridRef.GetState() method), and create a new DataSourceRequest object with the current filters, then use the .ToDataSourceResult() extension method of ours with that request - this would let you perform the same operation on the data as the grid does internally so you can fetch the same data. Ultimately, it's almost the same as using the OnRead event. If you already have all the data in the view model, the .ToDataSourceResult() method can let you do that filtering for the grid too, pretty easily.
Regards,
Marin Bratanov
Progress Telerik
[/quote]
Hi Marin!
Do you have a sample code of this?

Following Marin's suggestions I was able accomplish my goal. Thanks Marin btw! Here is a snipped of my code:
public List<
ExpandoObject
> GetFilteredData()
{
if (Data == null || !Data.Any())
{
// Return empty list if no data is available
return new List<
ExpandoObject
>();
}
// Apply filters from grid
var req = new DataSourceRequest();
var gridData = Grid.GetState();
var FilteredData = new List<
ExpandoObject
>();
req.Filters = new List<
IFilterDescriptor
>();
req.Filters.AddRange(gridData.FilterDescriptors);
FilteredData.AddRange((IEnumerable<
ExpandoObject
>)Data.ToDataSourceResult(req).Data);
return FilteredData;
}

Following Marin's suggestions I was able accomplish my goal. Thanks Marin btw! Here is a snipped of my code:
public List<
ExpandoObject
> GetFilteredData()
{
if (Data == null || !Data.Any())
{
// Return empty list if no data is available
return new List<
ExpandoObject
>();
}
// Apply filters from grid
var req = new DataSourceRequest();
var gridData = Grid.GetState();
var FilteredData = new List<
ExpandoObject
>();
req.Filters = new List<
IFilterDescriptor
>();
req.Filters.AddRange(gridData.FilterDescriptors);
FilteredData.AddRange((IEnumerable<
ExpandoObject
>)Data.ToDataSourceResult(req).Data);
return FilteredData;
}
[/quote]
Thanks! It worked!

I simplified this code and turned it into a generic extension method because its something I need often. ie: for selecting all rows matching the current filters. Works very easily this way.
public static List<T> FilteredData<T>(this TelerikGrid<T> grid)
{
var req = new DataSourceRequest { Filters = new List<IFilterDescriptor>(grid.GetState().FilterDescriptors) };
var filteredData = new List<T>((IEnumerable<T>)grid.Data.ToDataSourceResult(req).Data);
return filteredData;
}

private void OnGridStateChanged(GridStateEventArgs<OMSGrossMargin> args)
{
if (args.PropertyName == "FilterDescriptors")
{
var req = new DataSourceRequest
{
Filters = GridRef.GetState().FilterDescriptors.ToList()
};
GrossMarginTotal = ((IEnumerable<OMSGrossMargin>)OMSGrossMarginList
.ToDataSourceResult(req).Data)
.Sum(x => x.GMPPRO);
StateHasChanged();
}
}