I have remote binding and sorting set up and I can get data to populate but I am having trouble setting up my controller action correctly to handle the grid's sorting.
I set the DataSourceUrl in javascript because I don't want the grid to bind immediately on page load. $("#gridFind").igGrid('option', 'dataSource', '@Url.Action("GetData")');
What I am looking for is how to get sort information in the controller action. I know that I can go through Request.QueryString but that does not seem ideal. As I show in the action I can grab the page and pageSize using the model binder but the sort comes through different "sort(columnName)='desc'".
What is the preferred way to handle this? I have not seen a sample of how to do remote sorting in a controller action method.
Here is my grid and controller action
@(Html.Infragistics().Grid<ExistingData>()
.ID("gridFind")
.AutoGenerateColumns(false)
.Columns(column =>
{
column.For(fr => fr.FltRecId).Hidden(true);
column.For(fr => fr.DocNumCd).HeaderText("Document #");
column.For(fr => fr.TofDateTimeDt).HeaderText("Takeoff");
column.For(fr => fr.TrnorgNameNm).HeaderText("Organization");
column.For(fr => fr.PlatformType).HeaderText("Platform");
column.For(fr => fr.SideNumSn).HeaderText("Side Num");
column.For(fr => fr.Crew).HeaderText("Crew");
})
.Features(features =>
features
.Sorting()
.Type(OpType.Remote)
.Mode(SortingMode.Single)
.ColumnSettings(settings =>
settings.ColumnSetting().ColumnKey("TofDateTimeDt").AllowSorting(true).CurrentSortDirection("desc").FirstSortDirection("desc");
settings.ColumnSetting().ColumnKey("DocNumCd").AllowSorting(true).CurrentSortDirection("asc").FirstSortDirection("desc");
settings.ColumnSetting().ColumnKey("TrnorgNameNm").AllowSorting(true).FirstSortDirection("asc");
settings.ColumnSetting().ColumnKey("PlatformType").AllowSorting(true).FirstSortDirection("asc");
settings.ColumnSetting().ColumnKey("SideNumSn").AllowSorting(true).FirstSortDirection("asc");
settings.ColumnSetting().ColumnKey("Crew").AllowSorting(false);
});
.Paging()
.RecordCountKey("TotalRecordCount");
.Resizing();
.ResponseDataKey("ExistingData")
.Render()
)
[HttpGet]
public JsonResult GetData(
int page,
int pageSize)
int iTotalCount;
IList<ExistingData> data = m_repository.GetExistingData(out iTotalCount);
JsonResult result = new JsonResult
Data =
new
ExistingData = data.AsQueryable(),
TotalRecordCount = iTotalCount
},
JsonRequestBehavior = JsonRequestBehavior.AllowGet
};
return result;
}
hi,
you shouldn't do anything in order for this to work. you can refer to this sample:
http://samples.infragistics.com/jquery/grid/remote-sorting
basically you either need to mark your controller with the [GridDataSourceAction] attribute, or configure the grid in the controller and add the sorting feature. the grid logic parses the query string for sorting parameters, translates that to LINQ, etc. That's all done automatically for you.
let me know if you have any specific issues with this scenario.
Thanks,
Angel
Angel,
That does not work for us because we are not allowing our UI directly access the database. We retrieve a List from the database and call AsQueryable() on it to support the grid. We have fields in the grid that do not tie directly to database fields. This would make any LINQ auto-generated utterly fail.
if i won't use the attribute i'll went used remote sorting?
Hi,
it doesn't matter where the data is coming from. It can be a simple IQueryable of objects, which isn't bound to any entity framework. The data binding logic will figure this out.