Forum

July 12th, 2025
A A A
Avatar

Lost password?
Advanced Search

— Forum Scope —




— Match —





— Forum Options —





Minimum search word length is 3 characters - maximum search word length is 84 characters

The forums are currently locked and only available for read only access
sp_Feed Topic RSS sp_Related Related Topics sp_TopicIcon
Custom sorttype
24/07/2010
12:13
Avatar
cjm19682
Member
Members
Forum Posts: 9
Member Since:
28/03/2010
sp_UserOfflineSmall Offline
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 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 using a technique suggested by Tony in a separate post from OlegK - 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. Anyone go any ideas?
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
<html>
<head>
<title>Table Testbed</title>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<link rel="stylesheet" type="text/css" href="http://ajax.googleapis.com/ajax/libs/jqueryui/1.8/themes/south-street/jquery-ui.css">
<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.4.2/jquery.min.js"></script>
<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jqueryui/1.8/jquery-ui.min.js"></script>
<link rel="stylesheet" type="text/css" href="/thirdParty/jqGrid/ui.jqgrid.css" >
<script type="text/javascript" src="/thirdParty/jqGrid/grid.locale-en.js"></script>
<script type="text/javascript" src="/thirdParty/jqGrid/jquery.jqGrid.min.js"></script>
<script type="text/javascript">
$().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"}
]
});
});
</script>
</head>
<body>
<table id="playerTable"> 
<thead> 
<tr><th>Posn</th><th>Name</th></tr> 
</thead> 
<tbody> 
<tr><td>GK</td><td>Almunia</td></tr> 
<tr><td>GK</td><td>Fabianski</td></tr> 
<tr><td>DEF</td><td>Campbell</td></tr> 
<tr><td>DEF</td><td>Clichy</td></tr> 
<tr><td>MID</td><td>Denilson</td></tr> 
<tr><td>MID</td><td>Diaby</td></tr> 
<tr><td>STR</td><td>Arshavin</td></tr> 
<tr><td>STR</td><td>Bendtner</td></tr> 
</tbody> 
</table> 
</body>
</html>
Forum Timezone: Europe/Sofia

Most Users Ever Online: 994

Currently Online:
32 Guest(s)

Currently Browsing this Page:
1 Guest(s)

Top Posters:

OlegK: 1255

markw65: 179

kobruleht: 144

phicarre: 132

YamilBracho: 124

Renso: 118

Member Stats:

Guest Posters: 447

Members: 11373

Moderators: 2

Admins: 1

Forum Stats:

Groups: 1

Forums: 8

Topics: 10592

Posts: 31289

Newest Members:

, razia, Prankie, psky, praveen neelam, greg.valainis@pa-tech.com

Moderators: tony: 7721, Rumen[Trirand]: 81

Administrators: admin: 66

Comments are closed.
Privacy Policy   Terms and Conditions   Contact Information