We use cookies to give you the best experience on our website. If you continue to browse, then you agree to our privacy policy and cookie policy. Image for the cookie policy date
close icon

Filtered grid?

Is there anyway to get the model from the grid post filter?


5 Replies

KD Krishnaraj D Syncfusion Team November 26, 2010 12:47 PM UTC

Hi Greg Clouston,

Thanks for your interest in Syncfusion products.

Are looking for getting the grid model in the post action? If not, could you please provide more information on your requirement, because we are not clear about your query?

Regards,
Krishnaraj D




GC Greg Clouston November 26, 2010 01:37 PM UTC

I'm looking to get the altered model values from the grid to use elsewhere in the view. I would need to get the model values from the grid or apply the same changes (filters, groups, sort and etc.) to the model.



KD Krishnaraj D Syncfusion Team November 29, 2010 01:56 PM UTC

Hi Greg closuton,

We can get the altered GridPropertiesModel in our post action using OnActionMethodExecuted() method, but we cannot pass the altered GridPropertiesModel to the view since it is our custom Ajax request. Sp this request won't call any views. So we suggest you use to the initial filtering option(to get the altered grid values for filtering) by creating the GridPropertiesModel in the controller.

Please refer the below code snippets.

public ActionResult Index()
{
GridPropertiesModel gridModel = new GridPropertiesModel()
{
DataSource = new NorthwindDataContext().Orders.Take(200).ToList(),
Caption = "Orders",
AllowPaging = true,
AllowSorting = true,
AllowFiltering = true,
AutoFormat = Skins.Sandune
};

//Apply intial filters to grid
gridModel.Filters.FilterDescriptors.Add(new FilterDescriptor() { ColumnName = "EmployeeID", Operator = Syncfusion.Linq.FilterType.Equals, Value = 5 });

ViewData["GridModel"] = gridModel;
return View();
}

Get the GridPropertiesModel in the view as below.

<%=Html.Grid("Grid1", "GridModel", column =>
{

column.Add(c => c.OrderID).HeaderText("Order ID");
column.Add(c => c.CustomerID).HeaderText("Customer ID");
column.Add(c => c.EmployeeID).HeaderText("EmployeeID");
column.Add(c => c.ShipCity).HeaderText("Ship City");
})


%>

Please let us know if you have any queries.

Regards,
Krishnaraj D






GC Greg Clouston December 1, 2010 03:21 PM UTC

I'm not sure if this gets me where I need to be. Remember I also need to just setup a mirror image of the filtered, sorted and grouped grid data for use elsewhere. What I really need is a way to generate a dynamic LINQ statement that has the same filters, sorts and groups applied to it as the grid.

Thanks for the help. I'll keep plugging away on this.



KD Krishnaraj D Syncfusion Team December 2, 2010 11:54 AM UTC

Hi Greg Clouston,

Please refer our online sample in the below link.

http://mvc.syncfusion.com/sfmvcsamplebrowser/8.4.0.10/Grid_MVC/Samples/4.0/databinding/CustomBinding

In this sample, we are getting the altered Grid data by invoking the GetData() method in the post action. Please refer the below code snippets.

private IEnumerable GetData(PagingParams args)
{
int pagesize = args.PageSize == 0 ? 12 : Convert.ToInt32(args.PageSize);
IEnumerable data = new NorthwindDataContext().Orders.Take(200).ToList();

IQueryable ds = data.AsQueryable();

// if filterconditions exists filter the datasource using Do filtering
// extensions, which uses the expression based query generator used for apply filters
if (args.FilterDescriptors != null && args.FilterDescriptors.Count() > 0)
ds = ds.Where(args.FilterDescriptors);

//Sortcolumn, SortDirections properties are removed from Pagingparams
//New SortDescriptors property added in pagingparams. It contains list of Sort column values and their directions
if (args.SortDescriptors != null)
{
for (int i = 0; i < args.SortDescriptors.Count; i++)
{
var sortColumnName = args.SortDescriptors[i].ColumnName;
if (i == 0)
{

if (args.SortDescriptors[i].SortDirection == ListSortDirection.Ascending)
{
ds = ds.OrderBy(sortColumnName);

}
else if (args.SortDescriptors[i].SortDirection == ListSortDirection.Descending)
{
ds = ds.OrderByDescending(sortColumnName);
}
}
else
{
if (args.SortDescriptors[i].SortDirection == ListSortDirection.Ascending)
{
ds = ds.ThenBy(sortColumnName);
}
else if (args.SortDescriptors[i].SortDirection == ListSortDirection.Descending)
{
ds = ds.ThenByDescending(sortColumnName);
}
}
}
}
totalrecordCount = ds.Count();
if (totalrecordCount > 0)
data = ds.Skip(Convert.ToInt32(args.StartIndex)).Take(pagesize);
else
data = ds;

return data;
}


Please let us know if you have any further concerns.

Regards,
Krishnaraj D




Loader.
Live Chat Icon For mobile
Up arrow icon