jQuery EasyUI 教程
一些常見的編輯器(editor)添加到數(shù)據(jù)網(wǎng)格(datagrid),以便用戶編輯數(shù)據(jù)。 所有的編輯器(editor)都定義在 $.fn.datagrid.defaults.editors 對(duì)象中,這個(gè)可以繼承擴(kuò)展以便支持新的編輯器(editor)。 本教程將向您展示如何添加一個(gè)新的 numberspinner 編輯器到數(shù)據(jù)網(wǎng)格(datagrid)。
????$.extend($.fn.datagrid.defaults.editors, { ????????numberspinner: { ????????????init: function(container, options){ ????????????????var input = $('<input type="text">').appendTo(container); ????????????????return input.numberspinner(options); ????????????}, ????????????destroy: function(target){ ????????????????$(target).numberspinner('destroy'); ????????????}, ????????????getValue: function(target){ ????????????????return $(target).numberspinner('getValue'); ????????????}, ????????????setValue: function(target, value){ ????????????????$(target).numberspinner('setValue',value); ????????????}, ????????????resize: function(target, width){ ????????????????$(target).numberspinner('resize',width); ????????????} ????????} ????});
????<table id="tt" style="width:600px;height:250px" ????????????url="data/datagrid_data.json" title="Editable DataGrid" iconCls="icon-edit" ????????????singleSelect="true" idField="itemid" fitColumns="true"> ????????<thead> ????????????<tr> ????????????????<th field="itemid" width="60">Item ID</th> ????????????????<th field="listprice" width="80" align="right" editor="{type:'numberbox',options:{precision:1}}">List Price</th> ????????????????<th field="unitcost" width="80" align="right" editor="numberspinner">Unit Cost</th> ????????????????<th field="attr1" width="180" editor="text">Attribute</th> ????????????????<th field="status" width="60" align="center" editor="{type:'checkbox',options:{on:'P',off:''}}">Status</th> ????????????????<th field="action" width="80" align="center" formatter="formatAction">Action</th> ????????????</tr> ????????</thead> ????</table>
我們分配 numberspinner 編輯器到 'unit cost' 字段。 當(dāng)開始編輯一行,用戶可以通過 numberspinner 編輯器來編輯數(shù)據(jù)。