jquery - Toolbar search local data, retain value in cell even after searching -


i using toolbar searching on local data(because using optionloadonce: true). in grid, there 1 column 'transfer qty.' default editable.enter image description here

i want functionality like, suppose entered value in column 'transfer qty.' in 4th row lot no. name 'opstk_leher_mumbai-500' (for please refer above image) , if make search search-string 'p-35' , press enter, gives me first 3 row search result per search string , exclude 4th row in entered value. idea please refer following image... enter image description here

but if remove search string search box , press enter, gives me records but, value entered in 4th row in column 'transferqty' gets disappeared , want retain value anyhow.

if knows how this, kindly share valuable ideas.

to understanding per technical perspective, jqgrid code follows:

 var ogrid = $('#tblots'),   toppagerselector = '#' + $.jgrid.jqid(ogrid[0].id) + "_toppager", lastsel;  ogrid.jqgrid({     url: srelativepath + '/wsajax.asmx/getdataforgrid',     mtype: "post",     datatype: "json",     ajaxgridoptions: { contenttype: "application/json; charset=utf-8" },     serializegriddata: function (data) {         return json.stringify(data);     },     jsonreader: {         root: "d.rows",         page: "d.page",         total: "d.total",         records: "d.records"     },     colnames: ['sisdidforexch', 'sublotid', 'lot#', 'expiry date', 'qty.', 'transfer qty.'],     colmodel: [         { name: 'sisdidforexch', index: 'sisdidforexch', hidden: true },         { name: 'sublotid', index: 'sublotid', hidden: true },         { name: 'lotno', index: 'lotno', editable: false, sortable: false, width: 100},         {name: 'expiry', index: 'expiry', editable: false, search: false, align: 'center', formatter: 'date', formatoptions: { srcformat: 'm/d/y', newformat: 'd/m/y' }, sortable: false, width: 60 },         { name: 'bucketqty', index: 'bucketqty', editable: false, search: false, template: viewnumtemplate, width: 60 },         { name: 'transferqty', index: 'transferqty', editable: true, search: false, template: editnumtemplate, width: 60, editrules: { minvalue: 0.00 },             editoptions: {                 datainit: function (domelem) {                     $(domelem).on("blur", function () {                         calculatetotaltransferqty($("#tblots"));                     });                 }             }         }     ],     prmnames: { page: "pageindex", rows: "pagesize", sort: "sortindex", order: "sortdirection", search: "_search" },     search: false,     postdata: {         filters: null,         spname: 'getlotdetails',         paramxml: $xmldoc.html().tostring()     },     width: 'auto',     height: 'auto',     rownum: 1000,     sortname: '',     sortorder: 'asc',     page: 1,     gridview: true,     toppager: true,     autoencode: true,     ignorecase: true,     viewrecords: true,     caption: 'item lots',     editurl: 'clientarray',     footerrow: true,     loadonce: true,     gridcomplete: function () {         $("table#tblots tr:last").addclass('ireg-jqgrid-lastrow');         $("tr.footrow td").addclass('ireg-jqgrid-lastrow').addclass('ireg-jqgrid-footer');     },     loadcomplete: function (data) {         updatejqgridbuttonstate($(this), jqgridmode.none);         //following piece of code made 'transfer qty.' column default editable.          var l_oids = ogrid.jqgrid('getdataids'), i;         (i = 0; < l_oids.length; i++) {             ogrid.jqgrid('editrow', l_oids[i], true);         }         //set focus on first editable cell.          if (l_oids.length > 0)             $('#' + l_oids[0] + '_transferqty').get(0).focus();     },     onselectrow: function (rowid) {         if (rowid && rowid != lastsel) {             if (typeof lastsel !== "undefined") {                 $(this).jqgrid('restorerow', lastsel);             }             lastsel = rowid;         }         updatejqgridbuttonstate($(this), jqgridmode.none);     } }); ogrid.jqgrid('filtertoolbar', { stringresult: true, defaultsearch: 'cn', //groupop: 'or',     beforesearch: function () {         if (coldatatypes.length != 0 && coldatatypes != undefined) {             var orules = new array();             var postdata = $('#tblots').jqgrid('getgridparam', 'postdata'),              ocustfilter = $.parsejson(postdata.filters), colname, searchstr, operator, groupoperator = '';             (var = 0; < ocustfilter.rules.length; i++) {                 groupoperator = ocustfilter.groupop;                 searchstr = ocustfilter.rules[i].data;                 colname = ocustfilter.rules[i].field;                 operator = ocustfilter.rules[i].op;                 orules.push({ field: colname, op: operator, data: searchstr });             }              if (searchval != null && searchval != '') {                 var ofilter = { groupop: groupoperator, rules: orules };                 $.extend(postdata, { filters: json.stringify(ofilter) });                 $('#tblots').jqgrid('setgridparam', { search: true, postdata: postdata });                 $('#tblots').trigger("reloadgrid", [{ page: 1}]);             }         }         return true;     } }); //added afterrefresh function clear toolbar. ogrid.jqgrid('navgrid', toppagerselector, { add: false, edit: false, del: false, search: false,     afterrefresh: function () {         $(this)[0].cleartoolbar();     }   }, {}, {}, {}, {}); 

here updated code, way taught me do

ogrid.jqgrid('filtertoolbar', { stringresult: true, defaultsearch: 'cn', //groupop: 'or',     beforesearch: function () {        if (coldatatypes.length != 0 && coldatatypes != undefined) {             var orules = new array();             var postdata = $('#tblots').jqgrid('getgridparam', 'postdata'),                  ocustfilter = $.parsejson(postdata.filters), colname, searchstr, operator, groupoperator = '';             (var = 0; < ocustfilter.rules.length; i++) {                 groupoperator = ocustfilter.groupop;                 searchstr = ocustfilter.rules[i].data;                 colname = ocustfilter.rules[i].field;                 operator = ocustfilter.rules[i].op;                 //ireg-1821: uncommneted following code.                 var colindex = getcolumnindexbyname($('#tblots'), colname);                 var searchval = '', battachquote = false;                  if ('string' === coldatatypes[colindex]) {                     searchval = searchstr;                     battachquote = true;                 }                   orules.push({ field: colname, op: operator, data: searchstr, coldatatype: coldatatypes[colindex], attachquote: battachquote });             }              if (searchval != null && searchval != '') {                 var ofilter = { groupop: groupoperator, rules: orules };                 $.extend(postdata, { filters: json.stringify(ofilter) });                 $('#tblots').jqgrid('setgridparam', { search: true, postdata: postdata });                 $('#tblots').trigger("reloadgrid", [{ page: 1}]);             }         }          here code, taught me          var l_oids = ogrid.jqgrid('getdataids'), i;         (i = 0; < l_oids.length; i++) {             ogrid.jqgrid('saverow', l_oids[i], false, 'clientarray');         }          return true;     } }); 

the origin of problem seems me in using behavior described like

... 1 column 'transfer qty.' default editable.

you calls editrow rows of grid. set rows of grid in editing state. it's not recommended way because creates more problems.

the problem following. if starts inline editing jqgrid saves original values editing rows inside of internal savedrow parameter array of original values of editing rows. during inline editing user can make changes in editable fields, the user can cancel changes pressing esc key. in other words jqgrid have hold both old values , current (not yet saved) modified values. if user clicks on column header jqgrid sort column default. sorting means re-filling current page of grid. it's unclear whether current editable rows should saved or discarded. sorting typically prohibited during inline editing. same problem exist searching.

if want allow searching during inline editing , if need save data have call saverow in loop inside of beforesearch callback of filtertoolbar. explicitly calls editrow rows inside of loadcomplete have call saverow rows inside of beforesearch before trigger of reloadgrid.

one more remark code. seems me last row of grid have special meaning - contains footer information. set ireg-jqgrid-lastrow class on row inside of gridcomplete. row not editable. such scenario seems me implemented in way in jqgrid. can add footerrow: true option in grid. add separate div below of main grid, looks close picture included. main difference exist in separation of main data footer. can use footerdata method data in footer or can use userdataonfooter: true option. jqgrid footer automatically data userdata part of data returned server. see the old answer , this one or this one corresponding demos , implementation details.


Comments

Popular posts from this blog

javascript - Using jquery append to add option values into a select element not working -

Android soft keyboard reverts to default keyboard on orientation change -

Rendering JButton to get the JCheckBox behavior in a JTable by using images does not update my table -