This is one of the columns in my grid-
{ name: 'DueDate',
index: 'DueDate',
sortable: true,
sorttype: 'date',
editable: false,
width: 125,
formatter: 'date',
searchoptions: {
dataInit: function(element) {
$(element).datepicker({
dateFormat: 'mm/dd/yy'
});
}
}
}
I am trying to setup a custom filter like this-
var now = moment();
var formattedDate = now.format('MM/DD/YYYY');
var date = Date.parse(formattedDate);
var f = { groupOp: "OR", rules: [] };
f.rules.push({ field: 'DueDate', op: 'lt', data: date});
$grid[0].p.search = true;
$.extend($grid[0].p.postData, { filters: JSON.stringify(f) });
$grid.trigger('reloadGrid');
'DueDate' returned is a date string. so i need to parse it before i can compare. How do i do this? Is there even a way to do it?
DueDate is a Datetime object and the value from the controller is /Date(-62135568000000)/(json object) This is formatted into 'mm/dd/yy' format and this converts to a date string and looks like normal date. I have a drop down menu item with all the filter criteria. I click on one of the menu-items, which is to select all the rows that have DueDate < Today's date for which i need to parse 'DueDate' field's value.
For Testing, when i use this-
var now = moment();
var formattedDate = now.format('MM/DD/YYYY');
var rowdata = $grid.jqGrid('getRowData');
var dueDate = rowdata[0].DueDate; //just picking first row's due date
alert("DueDate: " + dueDate);//alerts "1/1/2015"
var d = Date.parse(formattedDate);
//var ts = dueDate.getTime(); --I get an error here- getTime() not supported for this object.
//this works fine- & I need something like this for filters
if (Date.parse(dueDate) < d) {
alert("It is due");
}
var f = { groupOp: "AND", rules: [] };
f.rules.push({ field: 'DueDate', op: 'lt', data: d });
f.rules.push({ field: 'HasMapping', op: 'eq', data: true });
$grid[0].p.search = true;
$.extend($grid[0].p.postData, { filters: JSON.stringify(f) });
$grid.trigger('reloadGrid');