在jqgrid中设置默认值
如果没有来自DB的数据,我需要为某些列显示0。因此,是否可以在colModel中为列定义默认值,这样我就不需要检查空值并在数组中将其设为零。没有任何直接的方法来定义任何列的默认值,但您可以通过某种方式来实现。例如 使用在jqgrid中设置默认值,jqgrid,Jqgrid,如果没有来自DB的数据,我需要为某些列显示0。因此,是否可以在colModel中为列定义默认值,这样我就不需要检查空值并在数组中将其设为零。没有任何直接的方法来定义任何列的默认值,但您可以通过某种方式来实现。例如 使用自定义格式化程序 您可以为特定列定义自己的格式化程序。通常这是一个函数。在该函数中,您可以检查列值是否为null或空,并返回一些默认值 例如: <script> jQuery("#grid_id").jqGrid({ ... colModel: [ ...
自定义格式化程序
您可以为特定列定义自己的格式化程序。通常这是一个函数。在该函数中,您可以检查列值是否为null或空,并返回一些默认值 例如:
<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>
jQuery(“网格id”).jqGrid({
...
colModel:[
...
{名称:'price',索引:'price',宽度:60,对齐:“中心”,可编辑:true,
格式化程序:currencyFmatter},
...
]
...
});
函数currencyFmatter(单元格值、选项、行对象)
{
//在此处执行某些操作以检查值并返回默认值
如果(cellvalue==“”| | cellvalue==“null”)
返回新的\u格式\u值
}
该列使用哪个格式化程序
?