Reputation: 4682
I need to display 0 for some columns if there is no data coming from DB. So is it possible to define a default value for a column in the colModel so that I don't need to check for empty values and making them zeros in the array.
Upvotes: 2
Views: 7077
Reputation: 4639
There is no any direct way to define default value for any column but you can do this by some way.like
using Custom Formatter
You can define your own formatter for a particular column. Usually this is a function.In that function you can check for column value if it is null or empty and return some default value.
For Example :
<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>
Upvotes: 2