Note that there are some explanatory texts on larger screens.

plurals
  1. POjqgrid: unformat is not called while sorting
    primarykey
    data
    text
    <p>As per the jqGrid documentation, if you provide a custom formatter in colOptions, you should also provide an 'unformat' key, which gets called during sort operation. However, I don't see this happening ie, the unformat function doesn't get called. Here is an extremely simple example:</p> <p>As you can see, the console.log line in the unformat_salary function never gets called. Even when you click on the Salary header to sort it. The sort seems to work but it's sorted lexically and I want a custom sort. Providing 'sorttype' as a function would do what I want but I'm wondering why unformat is not getting called when the Documentation specifically says it gets called during sort operations.</p> <p> JQGRID Test<br> </p> <pre><code> &lt;script type="text/javascript" src="http://trirand.com/blog/jqgrid/js/jquery.js"&gt;&lt;/script&gt; &lt;script type="text/javascript" src="http://trirand.com/blog/jqgrid/js/jquery-ui-1.8.1.custom.min.js"&gt;&lt;/script&gt; &lt;script type="text/javascript" src="http://trirand.com/blog/jqgrid/js/i18n/grid.locale-en.js"&gt;&lt;/script&gt; &lt;script type="text/javascript" src="http://trirand.com/blog/jqgrid/js/jquery.jqGrid.min.js"&gt;&lt;/script&gt; &lt;style type="text/css" media="screen"&gt; th.ui-th-column div{ white-space:normal !important; height:auto !important; padding:2px; } &lt;/style&gt; &lt;script type="text/javascript"&gt; $(function() { createGrid(); }); function createGrid() { $("#jqgrid-table").jqGrid({ colNames:['First&lt;br/&gt;Name', 'Last Name', 'Age', 'Salary', 'Type'], colModel:[ {name:'firstName',index:'firstName', width:100}, {name:'lastName',index:'lastName', width:100}, {name:'age', index:'age', width:50}, {name:'salary', index: 'salary', width:50, sortable:true, formatter: salary_formatter, unformat:unformat_salary}, {name:'type', index:'type', width: 56} ], width: 800, datatype:'local', pager: '#pager2', viewrecords: true, caption:"JSON Example" }); var searchOptions = { caption: 'Filter...', multipleSearch:true, closeAfterSearch:true, closeAfterReset:true, Find: 'Filter' }; jQuery("#jqgrid-table").jqGrid('navGrid', '#pager2', {search:true, edit:false, add:false, del:false, refresh:false}, null, null, null, searchOptions ); var data = getData(); for(var i =0; i &lt; data.length; i++) { var r = data[i]; jQuery("#jqgrid-table").addRowData(r.id, r); } } function getData() { return [ {id:1, firstName: 'John', lastName: 'XXX', age:'30', salary:'1500', type: 'Nice'}, {id:2, firstName: 'Ashley', lastName:'YYY', age:'31', salary:'1300', type:'Nicer'}, {id:3, firstName:'Smith', lastName:'ZZZ', age:'23', salary:'1301', type:'Nicest'}, {id:4, firstName:'Sarah', lastName:'Aster', age:'45', salary:'530', type:'Nicest'}, {id:5, firstName:'Michelle', lastName:'Crazy', age:'30', salary:'1423', type:'Nicest'} ]; } function salary_formatter(cellvalue) { return cellvalue.replace(/^(\d\d)/,'$1,'); } function unformat_salary(cellvalue) { console.log('U : ' + cellvalue); // THIS DOES NOT GET CALLED ! return Number(cellvalue.replace(/,/g,'')); } &lt;/script&gt; &lt;/head&gt; &lt;body&gt; &lt;div id='jqgrid-div'&gt; &lt;table id='jqgrid-table'&gt;&lt;/table&gt; &lt;div id="pager2"&gt;&lt;/div&gt; &lt;/div&gt; &lt;/body&gt; &lt;/html&gt; </code></pre>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload