2014-01-07 50 views
2

如果沒有來自數據庫的數據,我需要爲某些列顯示0。那麼是否有可能爲colModel中的列定義默認值,以便我不需要檢查空值並將它們設置爲數組中的零。在jqgrid中設置默認值

+0

哪'formatter'您使用的列? – Oleg

回答

2

沒有定義任何列缺省值任何直接的方式,但您可以通過使用Custom Formatter
您可以定義自己的格式化特定列一些way.like

做到這一點。通常這是一個函數。在那個函數中,你可以檢查列值是否爲空或空,並返回一些默認值。

例如:

<script> 
jQuery("#grid_id").jqGrid({ 
... 
colModel: [ 
    ... 
    {name:'price', index:'price', width:60, align:"center", editable: true, 
               formatter:currencyFmatter}, 
    ... 
] 
... 
}); 

function currencyFmatter (cellvalue, options, rowObject) 
{ 
    // do something here to check value and return default value 
    if(cellvalue == "" || cellvalue == "null") 
    return new_format_value 
} 
</script>