JQuery.BootGrid 可以使用哪些数据类型和数据格式化程序?还是数据类型和数据格式化字段实际上是 JQuery DataTypes 或其他一些属性?如果是这样,JQuery 数据类型是什么?(我找不到关于那个的文档)
我想将一列设置为货币(左侧有一个美元符号),我如何使用 JQuery.BootGrid 做到这一点?
但我想总体上了解数据类型/数据格式化程序。我是否必须为此了解 jqGrid 格式化程序,或者 bootGrid 是一个完全不同的产品?
JQuery.BootGrid 可以使用哪些数据类型和数据格式化程序?还是数据类型和数据格式化字段实际上是 JQuery DataTypes 或其他一些属性?如果是这样,JQuery 数据类型是什么?(我找不到关于那个的文档)
我想将一列设置为货币(左侧有一个美元符号),我如何使用 JQuery.BootGrid 做到这一点?
但我想总体上了解数据类型/数据格式化程序。我是否必须为此了解 jqGrid 格式化程序,或者 bootGrid 是一个完全不同的产品?
实际上,过去 8 个月我一直在使用 jquery bootgrid,并使用它的格式化程序功能重新格式化任何列。
在js文件中:
$("#grid").bootgrid({
money: function(column, row) {
return '$ '+row[column.id];
},
priceFormat: function(column, row) {
return '<span class="price-format">'+row[column.id]+'</span>';
}
});
在 html 中:
<thead>
<tr>
<th data-column-id="id" data-identifier="true" data-type="numeric">ID</th>
<th data-column-id="nama">Nama</th>
<th data-column-id="merk">Merk</th>
<th data-column-id="harga_limit" data-formatter="money">Harga Limit</th>
<th data-column-id="harga_satuan" data-formatter="money">Harga Satuan</th>
<th data-column-id="harga_total" data-formatter="priceFormat">Total</th>
<tr>
</thead>
Bootgrid 数据类型:
原来 data-type="numeric"
是唯一支持的类型:
从bootgrid github 上的搜索结果中,我了解到仅支持一种显式类型:numeric,其他任何内容都是 javascript 字符串。
数字数据类型与内部“数字”转换器一起使用 - 与字符串之间。
(在问题中,我的意思是此处定义的 JQuery 数据类型(单击此),但正如我刚才所说,这些与 Bootgrid 无关)
使用 Bootgrid 格式化程序
我知道格式化程序只是使用“this”和网格对象的任何 html(请参阅 Bootgrid 文档中的此处,然后向下滚动到“格式化程序”)。
所以你可以这样写代码:
// ... in continuation to the .bootgrid
$("#grid").bootgrid({
formatters: {
dollarformatter: function (column, row){
// "this" - is mapped to the grid instance
return '$ ' + this.rows[row][column];
},
myformatter: function (column, row)
{
// "this" - is mapped to the grid instance
// text - here is defined by the next column's content
return '<button id=\"mybutton' + row + '\"'
+ ' type=\"button\"'
+ ' class=\"btn btn-primary\"'
+ ' onclick=\"mybuttonclicked(' + row + ')\"'
+ '>'
+ this.rows[row][column + 1]
+ '</button>';
}
}
});
我不是前端 javascript 专家,所以如果有更清晰的方法来编写这些代码行而无需所有转义,请在此处告诉我。
谢谢你。