Jqgrid Search Formated Date Using Toolbar
Solution 1:
The problem: When the date is formatted from srcformat to the newformat a year is cut-ed according to the rules. When a search date is entered which contain only month and day the year is missing and the search is performed on the original data without year (since the conversion to original date). This causes the wrong searching results. Example if you enter 4.July as search string then according to the rules this string is converted to 4.7.1970 and search is performed to this date, which give not the desired results.
The solution: One possible solution is to define a virtual field which contain the formatted data and when a search is performed it should be applied not the the actual date field, but to the new build-ed virtual field. Below is the code:
{
name: 'DueDate',
index : 'mydate',
formatter: "date",
formatoptions: {
srcformat: 'd.m.Y',
newformat: gridOptions.dateFormat, // setting date format
},
sorttype: 'date',
searchoptions: {
sopt: ['eq'],
dataInit: function (e) {
//setting jquery-ui extension: multi-datepicker
}
}
},
{
name : 'mydate',
hidden: true,
jsonmap : function(item) {
return $.jgrid.parseDate.call($("#jqGrid")[0] , 'd.m.Y', item.DueDate , 'j.F');
}
},
Note the index property in DueDate. The #jqGrid is the id of the grid in definition in jsonmap in mydate virtual field
Post a Comment for "Jqgrid Search Formated Date Using Toolbar"