Private archive copy · Unofficial site · Content copyright belongs to Runoob Tutorial and the original authors · View Original

jQuery EasyUI Extension - Editable DataGrid

jQuery EasyUI Extension - Editable DataGrid (Editable DataGrid)


jQuery EasyUI Extensions jQuery EasyUI Extension


Usage

Create a datagrid in an html tag



    

        

            

                

                

                

                

                

            

        

    
Item IDProduct IDList PriceUnit CostAttribute

Make the datagrid editable



$('#tt').edatagrid({

    url: 'datagrid_data.json',

    saveUrl: ...,

    updateUrl: ...,

    destroyUrl: ...

});

Now you can double-click a datagrid row to start editing. You can also set the saveUrl, updateUrl, and destroyUrl properties to automatically synchronize data between the client and server.

property

This property extends from the datagrid; below are the properties added for the editable datagrid (edatagrid).

Name Type Description Default value
destroyMsg object The confirmation dialog message to display when destroying a row.

destroyMsg:{ norecord:{ // when no record is selected title:'Warning', msg:'No record is selected.' }, confirm:{ // when select a row title:'Confirm', msg:'Are you sure you want to delete?' } }| onSelect | event | autoSave | boolean | Set to true to automatically save the edited row when clicking outside the datagrid. | false| onSelect | event | url | string | A URL to retrieve data from the server. | null| onSelect | event | saveUrl | string | A URL to save data to the server and return the added row. | null| onSelect | event | updateUrl | string | A URL to update data on the server and return the updated row. | null| onSelect | event | destroyUrl | string | A URL to send the 'id' parameter to the server to destroy the row. | null| onSelect | event | tree | selector | The tree selector to display the corresponding tree component. | null| onSelect | event | treeUrl | string | A URL to retrieve tree data. | null| onSelect | event | treeDndUrl | string | A URL to handle drag and drop operations. | null| onSelect | event | treeTextField | string | Defines the text field name of the tree. | name| onSelect | event | treeParentField | string | Defines the parent node field name of the tree. | parentId |

Events

This event extends from the datagrid; below are the events added for the editable datagrid (edatagrid).

Name Parameters Description
onAdd index,row Triggered when a new row is added.
onEdit index,row Triggered when a row is edited.
onBeforeSave index Triggered before a row is saved; returning false cancels the save action.
onSave index,row Triggered when a row is saved.
onDestroy index,row Triggered when a row is destroyed.
onError index,row Triggered when a server error occurs.
 服务器应返回一个 'isError' 属性设置为 true 的行,表示发生错误。     

代码实例:


//server side code echo json_encode(array(     'isError' => true,     'msg' => 'error message.' ));

//client side code

$('#dg').edatagrid({

    onError: function(index,row){

        alert(row.msg);

    }

});

|

Method

This method extends from the datagrid; below are the methods added or overridden for the editable datagrid (edatagrid).

Name Parameters Description
options none Return the options object.
enableEditing none Enable datagrid editing.
disableEditing none Disable datagrid editing.
editRow index Edit the specified row.
addRow index Add a new row at the specified row index.
 如果 index 参数未指定,则向最后of位置追加一个新行。     

代码实例:


// append an empty row $('#dg').edatagrid('addRow');

// append an empty row as first row $('#dg').edatagrid('addRow',0);

// insert a row with default values $('#dg').edatagrid('addRow',{     index: 2,     row:{         name:'name1',         addr:'addr1'     } });| onSelect | event | saveRow | none | Save the edited row and post it to the server.| onSelect | event | cancelRow | none | Cancel the edited row.| onSelect | event | destroyRow | index | Destroy the currently selected rows.
If the index parameter is not specified, all selected rows are destroyed.

Code example:

// destroy all the selected rows

$('#dg').edatagrid('destroyRow');

// destroy the first row $('#dg').edatagrid('destroyRow', 0);

// destroy the specified rows $('#dg').edatagrid('destroyRow', [3,4,5]);

|

Download jQuery EasyUI Examples

jquery-easyui-edatagrid.zip


jQuery EasyUI Extensions jQuery EasyUI Extensions