jquery - Jqgrid search for dates is not working -


jq(function(){     var token = window.location.href     .substring(window.location.href             .lastindexof('=') + 1);     jq("#grid").jqgrid({         url:'/test/umpire/getfixtures',         datatype: 'json',         mtype: 'get',         colnames:['category',  'tournament','date', 'ground','team 1','team 2','umpire 1','umpire2','umpire 3','match refree','match obsrver','scorer 1','scorer 2'],         colmodel:[             {name:'categoryname',index:'categoryname', width:100,editable:true, editrules:{required:true}, editoptions:{size:10,readonly: 'readonly'}},             {name:'tournamentname',index:'tournamentname', width:200,editable:true, editrules:{required:true}, editoptions:{size:10}},             {name:'matchfromdate',index:'matchfromdate', width:100,formatter: "date",sorttype: "date",formatoptions:{srcformat: "u/1000", newformat: "m/d/y"},search:true, searchoptions: {sopt: ['eq','ne'],                 datainit : function (elem) {                    jq(elem).datepicker({dateformat:'mm-dd-yy', changeyear: true, changemonth: true, showbuttonpanel: true, showon: 'focus'});                 }}},             {name:'groundname',index:'groundname', width:100,editable:true, editrules:{required:true}, editoptions:{size:10}},             {name:'team1name',index:'team1name', width:150,editable:true, editrules:{required:true}, editoptions:{size:10}},             {name:'team2name',index:'team2name', width:150,editable:true, editrules:{required:true}, editoptions:{size:10}},             {name:'umpire1',index:'umpire1', width:100,formatter: function (cellvalue, options, rowobject) {                 return '<a href="/tnca/umpire/assign?id=' + options.rowid + '&name='+cellvalue+'&token=${token}">'+cellvalue+'</a>';             }},             {name:'umpire2',index:'umpire2', width:100,formatter: function (cellvalue, options, rowobject) {                 return '<a href="/tnca/umpire/assign?id=' + options.rowid + '&name='+cellvalue+'&token=${token}">'+cellvalue+'</a>';             }},             {name:'umpire3',index:'umpire3', width:100,formatter: function (cellvalue, options, rowobject) {                 return '<a href="/tnca/umpire/assign?id=' + options.rowid + '&name='+cellvalue+'&token=${token}">'+cellvalue+'</a>';             }},             {name:'matchrefree',index:'matchrefree', width:100,formatter: function (cellvalue, options, rowobject) {                 return '<a href="/tnca/umpire/assign?id=' + options.rowid + '&name='+cellvalue+'&token=${token}">'+cellvalue+'</a>';             }},             {name:'matchobserver',index:'matchobserver', width:100,formatter: function (cellvalue, options, rowobject) {                 return '<a href="/tnca/umpire/assign?id=' + options.rowid + '&name='+cellvalue+'&token=${token}">'+cellvalue+'</a>';             }},             {name:'scorer1',index:'scorer1', width:100,formatter: function (cellvalue, options, rowobject) {                 return '<a href="/tnca/umpire/assign?id=' + options.rowid + '&name='+cellvalue+'&token=${token}">'+cellvalue+'</a>';             }},             {name:'scorer2',index:'scorer2', width:100, formatter: function (cellvalue, options, rowobject) {                 return '<a href="/tnca/umpire/assign?id=' + options.rowid + '&name='+cellvalue+'&token=${token}">'+cellvalue+'</a>';             }},          ],            postdata:{         filters:'{"groupop":"and","rules":[{"field":"matchfromdate","op":"gt","data":"2007-09-06"},{"field":"matchfromdate","op":"lt","data":"2007-10-04"}]}'           },         editurl :"/test/home/?token=${token}",         rownum:20,         shrinktofit: true,         rowlist:[10,20,30],         height: 400,         autowidth: true,         rownumbers: true,         pager: '#pager',         sortname: 'matchfromdate',         viewrecords: true,         height:"100%",         sortorder: "asc",         caption:"<h2>assign umpire</h2>",         emptyrecords: "empty records",         loadonce: true,         loadcomplete: function(response) {     console.log(json.stringify(response))          },         jsonreader : {             root: "rows",             page: "page",             total: "total",             records: "records",             repeatitems: false,             cell: "cell",             id: "tournamentid"         }       }); 

hi above jqgrid code. have problem in searching date field(matchfromdate). went across many answers given in forum still couldn't achieve date search.

from json i'm getting date '1432683305000'

my jqgrid version 4.8.2 , using spring mvc.

can please me in resolving issue? thank in advance

it seems me main problem in code usage of formatoptions:{srcformat: "u/1000"} in code. such property can format code, save original values of date in local grid data. later try use jquery ui datepicker , have problem use date in format. can use @ syntax (see the documentation) still have 2 problems. first one: date displayed in datepicker in unix timestamp format not good. second problem: formatoptions:{srcformat: "u/1000"} saves dates unchanged (with hours, minutes, seconds of input date), want ignore hours, minutes, seconds , on input data.

so suggest use following properties:

formatter: "date", formatoptions: {newformat: "m/d/y"}, jsonmap: function (obj) {     var d = new date(parseint(obj.matchfromdate, 10));     return d.getfullyear() + "-" + (d.getmonth() + 1) + "-" + d.getdate(); } 

with jsonmap cut hour, min, ... parts of input data , convert string format close iso 8601.

the jsfiddle demo uses above code , other settings helpful you: column templates, onselect callback of datepicker , other. uses free jqgrid (currently in version 4.9 rc1) instead of guriddo jqgrid js 4.8.2, tried not use free jqgrid specific features (see wiki), should work guriddo jqgrid too.


Comments

Popular posts from this blog

angularjs - ADAL JS Angular- WebAPI add a new role claim to the token -

php - CakePHP HttpSockets send array of paramms -

node.js - Using Node without global install -