• easyui datagrid数据编辑


    以下为官方数据,不需要其他文件即可实现编辑数据

    <!DOCTYPE html>
    <html>
    <head>
    <meta charset="UTF-8">
    <title>Row Editing in DataGrid - jQuery EasyUI Demo</title>
    <link rel="stylesheet" type="text/css" href="../../themes/default/easyui.css">
    <link rel="stylesheet" type="text/css" href="../../themes/icon.css">
    <link rel="stylesheet" type="text/css" href="../demo.css">
    <script type="text/javascript" src="../../jquery.min.js"></script>
    <script type="text/javascript" src="../../jquery.easyui.min.js"></script>
    </head>
    <body>
    <h2>Row Editing in DataGrid</h2>
    <p>Click the row to start editing.</p>
    <div style="margin:20px 0;"></div>

    <table id="dg" class="easyui-datagrid" title="Row Editing in DataGrid" style="700px;height:auto"
    data-options="
    iconCls: 'icon-edit',
    singleSelect: true,
    toolbar: '#tb',
    url: 'datagrid_data1.json',
    method: 'get',
    onClickCell: onClickCell,
    onEndEdit: onEndEdit
    ">
    <thead>
    <tr>
    <th data-options="field:'itemid',80">Item ID</th>
    <th data-options="field:'productid',100,
    formatter:function(value,row){
    return row.productname;
    },
    editor:{
    type:'combobox',
    options:{
    valueField:'productid',
    textField:'productname',
    method:'get',
    url:'products.json',
    required:true
    }
    }">Product</th>
    <th data-options="field:'listprice',80,align:'right',editor:{type:'numberbox',options:{precision:2}}">List Price</th>
    <th data-options="field:'unitcost',80,align:'right',editor:{type:'numberbox',options:{precision:2}}">Unit Cost</th>
    <th data-options="field:'attr1',250,editor:'textbox'">Attribute</th>
    <th data-options="field:'status',60,align:'center',editor:{type:'checkbox',options:{on:'P',off:''}}">Status</th>
    </tr>
    </thead>
    </table>

    <div id="tb" style="height:auto">
    <a href="javascript:void(0)" class="easyui-linkbutton" data-options="iconCls:'icon-add',plain:true" onclick="append()">Append</a>
    <a href="javascript:void(0)" class="easyui-linkbutton" data-options="iconCls:'icon-remove',plain:true" onclick="removeit()">Remove</a>
    <a href="javascript:void(0)" class="easyui-linkbutton" data-options="iconCls:'icon-save',plain:true" onclick="acceptit()">Accept</a>
    <a href="javascript:void(0)" class="easyui-linkbutton" data-options="iconCls:'icon-undo',plain:true" onclick="reject()">Reject</a>
    <a href="javascript:void(0)" class="easyui-linkbutton" data-options="iconCls:'icon-search',plain:true" onclick="getChanges()">GetChanges</a>
    </div>

    <script type="text/javascript">
    var editIndex = undefined;
    function endEditing(){
    if (editIndex == undefined){return true}
    if ($('#dg').datagrid('validateRow', editIndex)){
    $('#dg').datagrid('endEdit', editIndex);
    editIndex = undefined;
    return true;
    } else {
    return false;
    }
    }
    function onClickCell(index, field){
    if (editIndex != index){
    if (endEditing()){
    $('#dg').datagrid('selectRow', index)
    .datagrid('beginEdit', index);
    var ed = $('#dg').datagrid('getEditor', {index:index,field:field});
    if (ed){
    ($(ed.target).data('textbox') ? $(ed.target).textbox('textbox') : $(ed.target)).focus();
    }
    editIndex = index;
    } else {
    setTimeout(function(){
    $('#dg').datagrid('selectRow', editIndex);
    },0);
    }
    }
    }
    function onEndEdit(index, row){
    var ed = $(this).datagrid('getEditor', {
    index: index,
    field: 'productid'
    });
    row.productname = $(ed.target).combobox('getText');
    }
    function append(){
    if (endEditing()){
    $('#dg').datagrid('appendRow',{status:'P'});
    editIndex = $('#dg').datagrid('getRows').length-1;
    $('#dg').datagrid('selectRow', editIndex)
    .datagrid('beginEdit', editIndex);
    }
    }
    function removeit(){
    if (editIndex == undefined){return}
    $('#dg').datagrid('cancelEdit', editIndex)
    .datagrid('deleteRow', editIndex);
    editIndex = undefined;
    }
    function acceptit(){
    if (endEditing()){
    $('#dg').datagrid('acceptChanges');
    }
    }
    function reject(){
    $('#dg').datagrid('rejectChanges');
    editIndex = undefined;
    }
    function getChanges(){
    var rows = $('#dg').datagrid('getChanges');
    alert(rows.length+' rows are changed!');
    }
    </script>
    </body>
    </html>

  • 相关阅读:
    Centos 环境变量
    Centos 多线程下载工具-axel
    【Sprint3冲刺之前】项目可行性研究报告
    【Sprint3冲刺之前】TDzhushou软件项目测试计划书
    【Sprint3冲刺之前】日历表的事件处理和管理(刘铸辉)
    【Sprint3冲刺之前】项目完成时间表
    【Sprint3冲刺之前】敏捷团队绩效考核(刘铸辉)
    【每日Scrum】第八天(4.29) TD学生助手Sprint2
    【每日Scrum】第七天(4.28)Sprint2总结性会议
    需求分析
  • 原文地址:https://www.cnblogs.com/xinyunyou/p/12381461.html
Copyright © 2020-2023  润新知