ligerui grid编辑怎么使他点击就可以编辑

 我来答
匿名用户
2015-02-14
展开全部
ligerui grid行编辑示例,具备新增行、删除行功能,可在修改某个cell之后,如果录入错误,可以提醒用户。
?
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171    <%@ page contentType="text/html; charset=UTF-8" %><%    String path = request.getContextPath();%><!DOCTYPE html><HTML><HEAD>    <TITLE> ZTREE DEMO - Simple Data</TITLE>    <meta http-equiv="content-type" content="text/html; charset=UTF-8">    冲世态<SCRIPT type="text/javascript">        var contextpath = "<%=path%>";    </SCRIPT>    <style type="text/css">    .myul li{float:left;width:100px;display:inline;}     </style>    <link href="<%=path %>/frameworks/ligerUI/skins/Aqua/css/ligerui-all.css" rel="stylesheet" type="text/css" />     <script src="<%=path %>/frameworks/jquery/jquery-1.4.4.min.js" type="text/javascript"></script>       <script src="<%=path %>/frameworks/ligerUI/js/core/base.js" type="text/javascript"></script>           <script src="<返桥%=path %>/frameworks/ligerUI/js/plugins/ligerDialog.js" type="text/javascript"></script>    <script src="<%=path %>/frameworks/ligerUI/js/plugins/ligerTextBox.js" type="text/javascript"></script>    <script src="<%=path %>/frameworks/ligerUI/js/plugins/ligerCheckBox.js" type="text/javascript"></script>    <script src="<%=path %>/frameworks/ligerUI/js/plugins/ligerComboBox.js" type="text/javascript"></script>    <script src="<%=path %>/frameworks/ligerUI/js/plugins/ligerGrid.js" type="text/javascript"></script>    <script src="<%=path %>/frameworks/ligerUI/js/plugins/ligerDateEditor.js" type="text/javascript"></script>    <script src="<%=path %>/frameworks/ligerUI/js/plugins/ligerSpinner.js" type="text/javascript"></script>    <script src="<%=path %>/frameworks/ligerUI/js/plugins/ligerResizable.js" type="text/javascript"></script>    散源<script src="<%=path %>/js/json2.js" type="text/javascript"></script>        <script src="<%=path %>/js/uuid.js" type="text/javascript"></script>      <SCRIPT type="text/javascript">        var manager, g;        $(document).ready(function(){            $("#leafOpt").click(function(){                $("#urlDom").show();            });            $("#dirOpt").click(function(){                $("#urlDom").hide();            });            //初始化grid            function itemclick(item)            {                alert(item.text);            }            var typeData = [{ val: 'url', text: 'URL' }, { val: 'btn', text: '按钮'}, { val: 'code', text: '分级编码'}];            var rowData = { Rows: []};            g =  manager = $("#maingrid").ligerGrid({                columns: [                { display: '名称', name: 'name', align: 'left', width: 120,editor: { type: 'text' } } ,                { display: '类型', width: 60, name: 'type',                    editor: { type: 'select', data: typeData, valueColumnName: 'val' },                    render: function (item)                    {                        for (var i = 0; i < typeData.length; i++)                        {                            if (typeData[i]['val'] == item.type)                                return typeData[i]['text']                        }                    }                },                { display: '值', name: 'value', width: 360, align: 'left',editor: { type: 'text' } }                ], sortName: 'name',enabledEdit: true, data: rowData,                onSelectRow: function (rowdata, rowindex)                {                    $("#txtrowindex").val(rowindex);                },                onBeforeEdit: onBeforeEdit, onBeforeSubmitEdit: onBeforeSubmitEdit,onAfterEdit: onAfterEdit,                width: '98%', height: '350', usePager: false, clickToEdit: true, checkbox: true            });        });        function deleteRow()        {            g.deleteSelectedRow();        }        function addNewRow()        {            g.addRow({                id : 0,                name:'',                type:'url',                value:''            });        }         //设置name前缀        function onBeforeEdit(e)        {             var data = manager.getData();             return true;        }        //限制年龄        function onBeforeSubmitEdit(e)        {             if (e.columnname == "Age")            {                if (e.value < 20 || e.value > 30) return false;            }            return true;        }        //编辑后事件         function onAfterEdit(e)        {            //当切换类型时,自动填充名称前缀            //alert(JSON.stringify(e.record));            //alert("after, e.column: "+JSON.stringify(e.column));            if(e.column.name=="type") {                var data = manager.getData();                var d = data[e.rowindex];                var name = '';                if(d.type=="url")                    name="url";                else if(d.type=="code")                    name="code_";                else if(d.type=="btn")                    name="btn_";                g.updateCell('name', name, e.record);             }            //当名称修改后,校验前缀是否与类型匹配            if (e.column.name == "name")            {                var d = e.record;                var cellObj = g.getCellObj(d, e.column);                //var name = d[e.column.name];                var name = $(cellObj).text();                if(name.length<1)                    return true;                if(d.type=="url" && name.indexOf(d.type)!=0) {                    alert('你刚才编辑的值录入不正确!(类型为URL时,名称必须以url开头(小写))');                    //cellObj.focus();                    //g.setCellEditing(d, e.column, editing);                    return false;                } else if(d.type=="code" && name.indexOf(d.type)!=0) {                    alert('你刚才编辑的值录入不正确!(类型为分级编码时,名称必须以code_开头(小写))');                    //g.setCellEditing(d, e.column, editing);                    return false;                } else if(d.type=="url" && name.indexOf(d.type)!=0) {                    alert('你刚才编辑的值录入不正确!(类型为按钮时,名称必须以btn_开头(小写))');                    //g.setCellEditing(d, e.column, editing);                    return false;                }            }            return true;        }     </script> </head><body>    <table>        <tr>            <td colspan=2>                <input type=radio id="dirOpt" name="typeOpt" checked><label for="dirOpt">目录节点</label>                <input type=radio id="leafOpt" name="typeOpt"><label for="leafOpt">叶子节点</label>            </td>        </tr>        <tr>            <td><label>节点名称</label></td>            <td><input type="text" id="nodeNameTxt" size="40"></td>        </tr>        <tr id="urlDom" style="display:none">            <td><label>叶子url</label></td>            <td><input type="text" id="urlTxt" size="70"></td>        </tr>        <tr>            <td><label>分级编码</label></td>            <td><input type="text" border="0" style="border:0;"  readonly id="nodeCodeTxt" size="40"></td>        </tr>    </table>    <div>    <a class="l-button" style="width:60px;float:left; margin-left:10px;" onclick="addNewRow()">新增行</a>    <a class="l-button" style="width:60px;float:left; margin-left:10px;" onclick="deleteRow()">删除行</a>    </div>    <div id="maingrid"></div></body></html>
已赞过 已踩过<
你对这个回答的评价是?
评论 收起
推荐律师服务: 若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询

为你推荐:

下载百度知道APP,抢鲜体验
使用百度知道APP,立即抢鲜体验。你的手机镜头里或许有别人想知道的答案。
扫描二维码下载
×

类别

我们会通过消息、邮箱等方式尽快将举报结果通知您。

说明

0/200

提交
取消

辅 助

模 式