jqGrid Data - formatter (custom)
jqGrid v4.6
by 1004lucifer
HTML
<script src="https://stackpath.bootstrapcdn.com/bootstrap/3.4.1/js/bootstrap.min.js"></script>
<link rel="stylesheet" href="https://stackpath.bootstrapcdn.com/bootstrap/3.4.1/css/bootstrap.min.css">
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/jqgrid/4.6.0/css/ui.jqgrid.css">
<script src="https://cdnjs.cloudflare.com/ajax/libs/jqgrid/4.6.0/js/i18n/grid.locale-kr.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/jqgrid/4.6.0/js/jquery.jqGrid.min.js"></script>
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/jqueryui/1.11.4/jquery-ui.min.css">
<table id="list"><tr><td></td></tr></table>
<div id="pager"></div>
JavaScript
var serverJsonData =
{
'page':'1',
'total': 2,
'records':'13',
'rows':[
{'id':'1','name':'Desktop Computers','price':'123.00'},
{'id':'2','name':'<var>laptop</var>','price':'256.00'},
{'id':'3','name':'LCD Monitor','price':'512.00'},
{'id':'4','name':'Speakers','price':'1024.00'}
]
};
$("#list").jqGrid({
url: '/echo/json/', // use JSFiddle echo service
datatype: 'json',
mtype: 'POST',
postData: { json: JSON.stringify(serverJsonData) },
colModel:[
{name:'name',label:'Name', width:150,editable: true},
{name:'id', sorttype:'int', editable: true,formatter:'integer'},
{name:'price', sorttype:'int', editable: true,formatter:currencyFmatter, unformat:unformatCurrency},
],
jsonReader : {
root:"rows",
page: "page",
total: "total",
records: "records",
repeatitems: false,
id: "0"
},
cellEdit: true,
caption : 'JSON Data',
height: 'auto',
autowidth: true,
rowNum: 5,
pager: '#pager'
});
function currencyFmatter (cellvalue, options, rowObject)
{
return "$"+cellvalue;
}
function unformatCurrency (cellvalue, options)
{
return cellvalue.replace("$","");
}