Note that there are some explanatory texts on larger screens.

plurals
  1. POjqGrid with Custom sorttype
    primarykey
    data
    text
    <p>I am using jqGrid 3.7.2 with local data. For some columns the default sorttypes are not sufficient. I need to provide a custom sorttype, which I understand from the documentation is possible. I don't know how to get it to work though. The code below is my best attempt at getting it to work - I can't make it call the custom sorting function though. The idea is to sort the 'Posn' field in the order 'GK'->'DEF'->'MID'->'STR'. Here is the code I'd like to get working:</p> <pre><code>&lt;!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd"&gt; &lt;html&gt; &lt;head&gt; &lt;title&gt;Table Testbed&lt;/title&gt; &lt;meta http-equiv="Content-Type" content="text/html; charset=UTF-8"&gt; &lt;link rel="stylesheet" type="text/css" href="http://ajax.googleapis.com/ajax/libs/jqueryui/1.8/themes/south-street/jquery-ui.css"&gt; &lt;script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.4.2/jquery.min.js"&gt;&lt;/script&gt; &lt;script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jqueryui/1.8/jquery-ui.min.js"&gt;&lt;/script&gt; &lt;link rel="stylesheet" type="text/css" href="/thirdParty/jqGrid/ui.jqgrid.css" &gt; &lt;script type="text/javascript" src="/thirdParty/jqGrid/grid.locale-en.js"&gt;&lt;/script&gt; &lt;script type="text/javascript" src="/thirdParty/jqGrid/jquery.jqGrid.min.js"&gt;&lt;/script&gt; &lt;script type="text/javascript"&gt; $().ready(function() { tableToGrid("#playerTable", { datatype: "local", sortable: true, hidegrid: false, multiselect: false, altRows: true, height: "100%", width: "155px", shrinkToFit: true, rowNum: 100, colNames: ['Posn','Name'], colModel: [ {name:'Posn', index:'Posn', width:100, sorttype: function(cell) { if (cell=='GK') return '0'; if (cell=='DEF') return '1'; if (cell=='MID') return '2'; if (cell=='STR') return '3'; } }, {name:'Name', index:'Name', width:200, sorttype:"text"} ] }); }); &lt;/script&gt; &lt;/head&gt; &lt;body&gt; &lt;table id="playerTable"&gt; &lt;thead&gt; &lt;tr&gt;&lt;th&gt;Posn&lt;/th&gt;&lt;th&gt;Name&lt;/th&gt;&lt;/tr&gt; &lt;/thead&gt; &lt;tbody&gt; &lt;tr&gt;&lt;td&gt;GK&lt;/td&gt;&lt;td&gt;Almunia&lt;/td&gt;&lt;/tr&gt; &lt;tr&gt;&lt;td&gt;GK&lt;/td&gt;&lt;td&gt;Fabianski&lt;/td&gt;&lt;/tr&gt; &lt;tr&gt;&lt;td&gt;DEF&lt;/td&gt;&lt;td&gt;Campbell&lt;/td&gt;&lt;/tr&gt; &lt;tr&gt;&lt;td&gt;DEF&lt;/td&gt;&lt;td&gt;Clichy&lt;/td&gt;&lt;/tr&gt; &lt;tr&gt;&lt;td&gt;MID&lt;/td&gt;&lt;td&gt;Denilson&lt;/td&gt;&lt;/tr&gt; &lt;tr&gt;&lt;td&gt;MID&lt;/td&gt;&lt;td&gt;Diaby&lt;/td&gt;&lt;/tr&gt; &lt;tr&gt;&lt;td&gt;STR&lt;/td&gt;&lt;td&gt;Arshavin&lt;/td&gt;&lt;/tr&gt; &lt;tr&gt;&lt;td&gt;STR&lt;/td&gt;&lt;td&gt;Bendtner&lt;/td&gt;&lt;/tr&gt; &lt;/tbody&gt; &lt;/table&gt; &lt;/body&gt; &lt;/html&gt; </code></pre>
    singulars
    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.
 

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