带有自定义排序类型的 jqGrid [英] jqGrid with Custom sorttype

查看:27
本文介绍了带有自定义排序类型的 jqGrid的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我将 jqGrid 3.7.2 与本地数据一起使用.对于某些列,默认排序类型是不够的.我需要提供一个自定义的 sorttype,我从文档中了解到这是可能的.我不知道如何让它工作.下面的代码是我让它工作的最佳尝试 - 但我不能让它调用自定义排序函数.这个想法是按照'GK'->'DEF'->'MID'->'STR'的顺序对'Posn'字段进行排序.这是我想要开始工作的代码:

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:

<!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>

推荐答案

可能您在 Tony 对我的主题的回答 http://www.trirand.com/blog/?page_id=393/help/custom-local-sort-with-respect-of-the-function-as-index/.你的问题很容易解决.我建议使用 index 作为本地 jqGrid 数据的自定义排序函数在 3.7.1 版中工作正常,但在 jqGrid 3.7.2 版中不能更多.sorttype作为函数在jqGrid版本3.7.2发布后实现.

Probably you read about the usage of sorttype as a function in Tony's answer to my thread http://www.trirand.com/blog/?page_id=393/help/custom-local-sort-with-respect-of-the-function-as-index/. Your problem could be very easy solved. My suggestion to use index as a function for custom sorting of local jqGrid data work fine in the version 3.7.1, but not more in the version 3.7.2 of jqGrid. The feature sorttype as a function is implemented in the jqGrid after the release of the version 3.7.2.

所以为了能够使用 sorttype 作为一个函数,你必须从 http://github.com/tonytomov/jqGrid/tree/master.这是 jqGrid 的未压缩版本.如果您不熟悉 jqGrid 的未压缩版本,我建议您阅读 http://www.trirand.com/jqgridwiki/doku.php?id=wiki:how_to_install#development_installation 以了解应该包含哪些 js 文件以及应该包含的顺序.在 http://www.ok-soft-gmbh.com/jqGrid/CustomSorttype1 下.htm 您可以找到自定义函数真正起作用的代码的工作示例.

So to be able to use sorttype as a function you have to download the latest version of jqGrid from http://github.com/tonytomov/jqGrid/tree/master. This is an uncompressed version of jqGrid. If you not familier with uncompressed version of jqGrid I'll recommend you to read http://www.trirand.com/jqgridwiki/doku.php?id=wiki:how_to_install#development_installation to undertand which of js files and in the which order you should include. Under http://www.ok-soft-gmbh.com/jqGrid/CustomSorttype1.htm you can find a working example of your code where the custom function really work.

这篇关于带有自定义排序类型的 jqGrid的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆