非常教程

jQuery EasyUI 教程教程

jQuery EasyUI 扩展 – 可编辑的数据网格

jQuery EasyUI 扩展 – 可编辑的数据网格

jQuery EasyUI 扩展 - 可编辑的数据网格(Editable DataGrid)


jQuery EasyUI 扩展 – 可编辑的数据网格

jQuery EasyUI 扩展

jQuery EasyUI 扩展 – 可编辑的数据网格

用法

在 html 标签中创建数据网格(datagrid)

    <table id="tt" style="width:600px;height:200px"
            title="Editable DataGrid"
            singleSelect="true">
        <thead>
            <tr>
                <th field="itemid" width="100" editor="{type:'validatebox',options:{required:true}}">Item ID</th>
                <th field="productid" width="100" editor="text">Product ID</th>
                <th field="listprice" width="100" align="right" editor="{type:'numberbox',options:{precision:1}}">List Price</th>
                <th field="unitcost" width="100" align="right" editor="numberbox">Unit Cost</th>
                <th field="attr1" width="150" editor="text">Attribute</th>
            </tr>
        </thead>
    </table>

让数据网格(datagrid)可编辑

$('#tt').edatagrid({
    url: 'datagrid_data.json',
    saveUrl: ...,
    updateUrl: ...,
    destroyUrl: ...
});

现在您可以双击数据网格行开始编辑操作。您也可以设置 saveUrl、updateUrl、destroyUrl 属性来自动同步客户端与服务器端的数据。

属性

该属性扩展自数据网格(datagrid),下面是为可编辑的数据网格(edatagrid)添加的属性。

名称 类型 描述 默认值
destroyMsg object 当销毁一行时要显示的确认对话框消息。
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?'
    }
}
autoSave boolean 设置为 true,则当点击数据网格外部时自动保存编辑行。 false
url string 一个 URL,从服务器检索数据。 null
saveUrl string 一个 URL,向服务器保存数据,并返回添加的行。 null
updateUrl string 一个 URL,向服务器更新数据,并返回更新的行。 null
destroyUrl string 一个 URL,向服务器传送 'id' 参数来销毁该行。 null
tree selector 显示对应的树组件的树选择器。 null
treeUrl string 一个 URL,检索树的数据。 null
treeDndUrl string 一个 URL,处理拖放操作。 null
treeTextField string 定义树的文本字段名称。 name
treeParentField string 定义树的父节点字段名称。 parentId

事件

该事件扩展自数据网格(datagrid),下面是为可编辑的数据网格(edatagrid)添加的事件。

名称 参数 描述
onAdd index,row 当添加一个新行时触发。
onEdit index,row 当编辑一行时触发。
onBeforeSave index 一行被保存之前触发,返回 false 则取消保存动作。
onSave index,row 当保存一行时触发。
onDestroy index,row 当销毁一行时触发。
onError index,row 当发生服务器错误时触发。
服务器应返回一个 '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);
    }
});

方法

该方法扩展自数据网格(datagrid),下面是为可编辑的数据网格(edatagrid)添加或重写的方法。

名称 参数 描述
options none 返回选项(options)对象。
enableEditing none 启用数据网格(datagrid)编辑。
disableEditing none 禁用数据网格(datagrid)编辑。
editRow index 编辑指定的行。
addRow index 向指定的行索引添加一个新行。
如果 index 参数未指定,则向最后的位置追加一个新行。

代码实例:

// 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'
    }
});
saveRow none 保存编辑行,发布到服务器。
cancelRow none 取消编辑行。
destroyRow index 销毁当前选中的行。
如果 index 参数未指定,则销毁所有选中的行。

代码实例:

// 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]);

下载 jQuery EasyUI 实例

jquery-easyui-edatagrid.zip


jQuery EasyUI 扩展 – 可编辑的数据网格

jQuery EasyUI 扩展
jQuery EasyUI 扩展 – 可编辑的数据网格
jQuery EasyUI 教程

jQuery EasyUI 是一个基于 jQuery 的框架,集成了各种用户界面插件。jQuery EasyUI 框架提供了创建网页所需的一切,帮助您轻松建立站点。

jQuery EasyUI 教程目录

1.jQuery EasyUI 教程
2.jQuery EasyUI 基础插件 – Draggable 可拖拽
3.jQuery EasyUI 基础插件 – Easyloader 加载器
4.jQuery EasyUI 基础插件 – Parser 解析器
5.jQuery EasyUI 布局插件 – Tabs 标签页/选项卡
6.jQuery EasyUI 布局插件 – Panel 面板
7.jQuery EasyUI 基础插件 – Tooltip 提示框
8.jQuery EasyUI 基础插件 – Progressbar 进度条
9.jQuery EasyUI 基础插件 – Searchbox 搜索框
10.jQuery EasyUI 基础插件 – Pagination 分页
11.jQuery EasyUI 基础插件 – Resizable 可调整尺寸
12.jQuery EasyUI 基础插件 – Droppable 可释放
13.jQuery EasyUI 菜单与按钮插件 – Linkbutton 链接按钮
14.jQuery EasyUI 菜单与按钮插件 – Menu 菜单
15.jQuery EasyUI 布局插件 – Layout 布局
16.jQuery EasyUI 布局插件 – Accordion 折叠面板
17.jQuery EasyUI 菜单与按钮插件 – Splitbutton 分割按钮
18.jQuery EasyUI 菜单与按钮插件 – Menubutton 菜单按钮
19.jQuery EasyUI 表单插件 – Datebox 日期框
20.jQuery EasyUI 表单插件 – Numberbox 数字框
21.jQuery EasyUI 表单插件 – Combogrid 组合网格
22.jQuery EasyUI 表单插件 – Combotree 组合树
23.jQuery EasyUI 表单插件 – Combobox 组合框
24.jQuery EasyUI 表单插件 – Combo 组合
25.jQuery EasyUI 表单插件 – Validatebox 验证框
26.jQuery EasyUI 表单插件 – Form 表单
27.jQuery EasyUI 数据网格与树插件 – Datagrid 数据网格
28.jQuery EasyUI 窗口插件 – Messager 消息框
29.jQuery EasyUI 窗口插件 – Dialog 对话框
30.jQuery EasyUI 窗口插件 – Window 窗口
31.jQuery EasyUI 表单插件 – Slider 滑块
32.jQuery EasyUI 表单插件 – Timespinner 时间微调器
33.jQuery EasyUI 表单插件 – Numberspinner 数值微调器
34.jQuery EasyUI 表单插件 – Spinner 微调器
35.jQuery EasyUI 表单插件 – Calendar 日历
36.jQuery EasyUI 表单插件 – Datetimebox 日期时间框
37.jQuery EasyUI 扩展 – 可编辑的树
38.jQuery EasyUI 扩展 – 可编辑的数据网格
39.jQuery EasyUI 扩展 – 数据网格视图
40.jQuery EasyUI 扩展 – Portal
41.jQuery EasyUI 插件
42.jQuery EasyUI 数据网格与树插件 – Treegrid 树形网格
43.jQuery EasyUI 数据网格与树插件 – Tree 树
44.jQuery EasyUI 数据网格与树插件 – Propertygrid 属性网格
45.jQuery EasyUI 扩展 – RTL 支持
46.jQuery EasyUI 扩展 – DWR 加载器
47.jQuery EasyUI 扩展 – 主题
48.jQuery EasyUI 扩展 – 树形网格行拖放
49.jQuery EasyUI 扩展 – 数据网格行拖放
50.jQuery EasyUI 扩展 – 数据网格行过滤
51.jQuery EasyUI 扩展 – Ribbon