top
Loading...
jQuery EasyUI 數據網格 – 擴展編輯器

jQuery EasyUI 數據網格 - 擴展編輯器

一些常見的編輯器(editor)添加到數據網格(datagrid),以便用戶編輯數據。 所有的編輯器(editor)都定義在 $.fn.datagrid.defaults.editors 對象中,這個可以繼承擴展以便支持新的編輯器(editor)。 本教程將向您展示如何添加一個新的 numberspinner 編輯器到數據網格(datagrid)。

繼承擴展 numberspinner 編輯器

    $.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);
            }
        }
    });

在 html 標記中創建數據網格(DataGrid)

    <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' 字段。 當開始編輯一行,用戶可以通過 numberspinner 編輯器來編輯數據。

北斗有巢氏 有巢氏北斗