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.
Unfortunately, activation email could not send to your email. Please try again.

Filtered grid?

Thread ID:

Created:

Updated:

Platform:

Replies:

97425 Nov 25,2010 02:45 PM Dec 2,2010 06:54 AM ASP.NET MVC (Classic) 5
loading
Tags: Grid
Greg Clouston
Asked On November 25, 2010 02:45 PM

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


Krishnaraj D [Syncfusion]
Replied On November 26, 2010 07:47 AM

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



Greg Clouston
Replied On November 26, 2010 08:37 AM

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.


Krishnaraj D [Syncfusion]
Replied On November 29, 2010 08:56 AM

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





Greg Clouston
Replied On December 1, 2010 10:21 AM

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.


Krishnaraj D [Syncfusion]
Replied On December 2, 2010 06:54 AM

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




CONFIRMATION

This post will be permanently deleted. Are you sure you want to continue?

Sorry, An error occured while processing your request. Please try again later.

You are using an outdated version of Internet Explorer that may not display all features of this and other websites. Upgrade to Internet Explorer 8 or newer for a better experience.

;