jQWidgets Forums
jQuery UI Widgets › Forums › Grid › Initial Filter with virtualmode
Tagged: Initial Filter with virtualmode
This topic contains 1 reply, has 2 voices, and was last updated by Peter Stoev 10 years, 6 months ago.
-
Author
-
Hi,
I would like to apply two initial filters in my grid with virtual mode.
// prepare the data var source_dr = { dataType: "json", datafields: [ { name: 'id', type: 'number' }, { name: 'user', type: 'number' }, { name: 'date', type: 'date' }, { name: 'start', type: 'number' }, { name: 'end', type: 'number' }, { name: 'hours', type: 'number' } ], id: 'id', url: '/controller/GetCurrentRecords', // update the grid and send a request to the server. filter: function () { $("#grid").jqxGrid('updatebounddata', 'filter'); }, // update the grid and send a request to the server. sort: function () { $("#grid").jqxGrid('updatebounddata', 'sort'); }, root: 'Rows', beforeprocessing: function (data) { source_dr.totalrecords = data.TotalRows; } }; var dataAdapter_dr = new $.jqx.dataAdapter(source_dr, { downloadComplete: function (data) { source_dr.totalrecords = data.TotalRows; } }); var userColumnFilter = function () { var filtergroup = new $.jqx.filter(); var filter_or_operator = 1; var filtervalue = 2; var filtercondition = "EQUAL"; var filter = filtergroup.createfilter("stringfilter", filtervalue, filtercondition); filtergroup.addfilter(filter_or_operator, filter); return filtergroup; }(); var dateColumnFilter = function () { var filtergroup = new $.jqx.filter(); var filter_or_operator = 1; var filtervalue = "2014-11-03"; var filtercondition = "EQUAL"; var filter = filtergroup.createfilter("stringfilter", filtervalue, filtercondition); filtergroup.addfilter(filter_or_operator, filter); return filtergroup; }(); $("#grid").jqxGrid( { width: '100%', height: '100%', source: dataAdapter_dr, theme: theme, altRows: true, pageSize: 25, sortable: true, filterable: true, pageable: true, pagermode: 'simple', virtualmode: true, rendergridrows: function (obj) { return obj.data; }, localization: getLocalization(), columns: [ { text: 'User', dataField: 'user', filter: userColumnFilter, width: 200 }, { text: 'Date', dataField: 'date', cellsFormat: 'D', filter: dateColumnFilter, width: 250 }, { text: 'Start', dataField: 'start', width: 120 }, { text: 'End', dataField: 'end', width: 120 }, { text: 'Hours', dataField: 'hours', cellsFormat: 'F2', cellsAlign: 'right' } ] });
The problem starts by the querystring: {undefinedoperator=and&filtervalue0=2014-11-03&filtercondition0=EQUAL&filteroperator0=1&filterscount=1&groupscount=0&pagenum=0&pagesize=25&recordstartindex=0&recordendindex=25&_=1415097777057}
The consequence is that the buildquery function can’t run properly because filterDataField can’t be found in the querystring.
public JsonResult GetCurrentRecords(string sortdatafield, string sortorder, int pagesize, int pagenum) { var query = Request.QueryString; var dbResult = db.Database.SqlQuery<workrecords>(this.BuildQuery(query)); var workrecords1 = (from workrecords in dbResult select new { workrecords.id, workrecords.user, workrecords.date, workrecords.start, workrecords.end, workrecords.hours }); var total = dbResult.Count(); if (sortorder != null && sortorder != "") { if (sortorder == "asc") { workrecords1 = workrecords1.OrderBy(o => o.GetType().GetProperty(sortdatafield).GetValue(o, null)); } else { workrecords1 = workrecords1.OrderByDescending(o => o.GetType().GetProperty(sortdatafield).GetValue(o, null)); } } workrecords1 = workrecords1.Skip(pagesize * pagenum).Take(pagesize); var result = new { TotalRows = total, Rows = workrecords1 }; return Json(result, JsonRequestBehavior.AllowGet); }
Hello hf,
My suggestion for you is to implement the dataAdapter’s formatData callback to format the Grid params in the way you wish. That will allow you to modify the query string in the way you wish.
Best Regards,
Peter StoevjQWidgets Team
http://www.jqwidgets.com -
AuthorPosts
You must be logged in to reply to this topic.