2011-03-31 70 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作爲函數的最簡單方法是從函數轉換後的數據返回,該數據應該用於在相應的比較操作中定義,以定義網格中該行的順序。