ASP.net
Awesome
Learn
Forum
Buy
Demos
Sign In
☾
☀
Switch to
Dark
Light
Mode
this site works best with javascript enabled
Ask Question
Grouping and sorting not working for dynamic columns in grid
Title:
B
I
{code}
?
Hi I am generating dynamic columns in my grid as in code shown below:- private GridModel<GridArrayRow> BuildGridModel(GridParams g) { ServiceReferences.ReportServiceReference.Report reportContract = null; ApplicationExceptionHandler.Handle(() => { ServiceProcessComponent.Use<ReportServiceClient>( reportService => { reportContract = reportService.GetUserReport(); }); }); var columns = new List<Column>(); for (int i = 1; i < reportContract.ReportTable.Columns.Count; i++) { columns.Add(new Column { Header = reportContract.ReportTable.Columns[i].ToString(), Groupable = true, ClientFormatFunc = "getVal(" + i + ")" }); } var items = new List<GridArrayRow>(); for (int i = 0; i < reportContract.ReportTable.Rows.Count; i++) { items.Add(new GridArrayRow { Id = reportContract.ReportTable.Rows[i][0].ToString(), Values = reportContract.ReportTable.Rows[i].ItemArray.Select(x => x.ToString()).ToArray() }); } g.Columns = columns.ToArray(); return new GridModelBuilder<GridArrayRow>(items.AsQueryable(), g).Build(); } and my view looks like:- @(Html.Awe().Grid("UserReportGrid") .Url(Url.Action("GetGridItems", "Report")) .Persistence(Persistence.Session) .Groupable(true) .ShowGroupBar(true) .LoadOnParentChange(false) .Height(350)) but grouping and sorting is not working for this
Save Changes
Cancel
Tanuj Shrivastava
asked at 26 Jul 2016
you're not setting the Column.Bind, so the Column doesn't know what to sort on
at 26 Jul 2016
Omu
so can I use the bind property with ClientformatFunc, Is it possible ?
at 26 Jul 2016
Tanuj Shrivastava
I did something like " columns.Add(new Column { Header = reportContract.ReportTable.Columns[i].ToString(), Groupable = true, Bind = '.'+ reportContract.ReportTable.Columns[i].ToString(), ClientFormatFunc = "getVal(" + i + ")" });" but still its not working, on dragging column to group bar , getgriditem method is called again, but data doesnot update
at 26 Jul 2016
Tanuj Shrivastava
keep the browser console open an you will see all the errors, you can also put breakpoints in BuildGridModel; Groupable is true by default; read this http://aspnetawesome.com/learn/mvc/Grid#Data-binding to see how Bind and sorting works; and presuming that the service you're using doesn't support linq, you need to look into this: http://demo.aspnetawesome.com/GridDemo/CustomQuerying
at 26 Jul 2016
Omu
It means without binding with model properties. grouping and sorting won't work , right ?
at 26 Jul 2016
Tanuj Shrivastava
yes, you can see in the customquerying demo, g.SortNames has the sorted columns column.Bind values, so you're using those values to query your data
at 26 Jul 2016
Omu
Answers
please
Sign In
to leave an answer
By accessing this site, you agree to store cookies on your device and disclose information in accordance with our
cookie policy
and
privacy policy
.
OK