2011-03-31 67 views
3

jqGrid的自定义格式选项“无格”犯规时函数提供的工作。jqGrid的自定义格式选项“无格”不工作

我提供功能此选项。 custom formatter example 假设工作,但它不工作。

我有非格式化函数的主要目的是给排序函数(当你通过点击可排序的列标题进行排序时)调用提供给colModel的非格式化和格式化程序的适当值。

这里是我的代码,(所有的模块都包含了jQuery UI的和的jqGrid。)

<link href="../css/jquery-ui-1.8.11.custom.css" rel="stylesheet" type="text/css"/> 
<link href="../css/ui.jqgrid.css" rel="stylesheet" type="text/css"/> 
<script type="text/javascript" src="../js/jquery-1.5.2.js"></script> 
<script type="text/javascript" src="../js/jquery-ui-1.8.11.custom.min.js"></script> 
<script type="text/javascript" src="../js/jquery.jqGrid.min.js"></script> 


    $("#GridTable").jqGrid({ 
    datatype: "local", 
    colNames: ['id', 'col1', 'col2', 'col3', 'col4'], 
    colModel: [{name:'id',index:'id', align:'left', width:'260px'}, 
       {name:'col1',index:'col1', width:'170px'}, 
       {name:'col2',index:'col2', width:'160px'}, 
       {name:'col3',index:'col3', sorttype:'float', width:'110px',unformat: unformatterFunction, formatter: formatterFunction }, 
       {name:'col4',index:'col4', sorttype:'float', width:'110px'} 
      ], 
    altRows: true, 
    caption: "Test Data", 
    height: '100%', 
    autowidth : true, 
    shrinkToFit: true, 
}); 

function unformatterFunction(cellvalue, options, rowObject){ 
    if(cellvalue=="-"){ 
     return "0"; 
    } 
    return cellvalue; 
} 

function formatterFunction(cellvalue, options, rowObject){ 
    if(cellvalue > 15){ 
     return "-"; 
    } 
    return cellvalue; 
} 

我花很多时间来跟踪该呼叫转变grid.base.js,发现没有办法,去jquery.fmatter.js其中unformatFunction被调用的每一行。 我的疑问是非格式化功能在排序时不会被调用。

我只是通过编辑the example证实,它不工作,什么是可怕的错误。我想不出任何错误。它根本不调用colModel中指定的无格式函数。

+0

如果我想更改CSS的jqGrid的的添加/编辑形式的? – 2012-08-13 05:53:45

回答

1

如果需要定制,以本地的jqGrid排序定制unformatter的用法是错误的方式。你需要的是使用sorttype作为功能。看看the old answer包括演示或this one

使用sorttype作为函数的最简单方法是从函数转换后的数据返回,该数据应该用于在相应的比较操作中定义,以定义网格中该行的顺序。