jquery Easyui-datagrid Manually add delete reset line

Source: Internet
Author: User

1. The implementation of the following

2. Interface:

<div region= "center" >
<table id= "tt" >
</table>
</div>

3. The introduced JS file

<link rel= "stylesheet" type= "Text/css" href= "Http://www.cnblogs.com/script/themes/default/easyui.css"/>

<link rel= "stylesheet" type= "Text/css" href= "Http://www.cnblogs.com/script/themes/icon.css"/>

<script type= "Text/javascript" src= "Http://www.cnblogs.com/script/jquery-1.4.2.min.js" </script>

<script type= "Text/javascript" src= "Http://www.cnblogs.com/script/jquery.easyui.min.js" </script>

<script type= "Text/javascript" src= "http://www.cnblogs.com/script/locale/easyui-lang-zh_CN.js" mce_src= "script /locale/easyui-lang-zh_cn.js "></script>

4. The implementation of the JS code:

<script type= "Text/javascript" > var id;        $ (document). Ready (function () {//Initialize the urban area var dialogparams = window.dialogarguments;        var obj = dialogparams[0];        var Xmaqrypartjson = obj[' Xmaqrypartjson ']; $ ("[Id^=gfzrzt_]"). each (function () {document.getElementById ($ (). attr ("id")). The value = obj[$ (this). attr ("id").        Replace ("Gfzrzt_", "")]}) id = obj[' id '];    InitData (Xmaqrypartjson)}); function InitData (Xmaqjson) {if (Xmaqjson = = "| | xmaqjson = = Undefined | | xmaqjson = = NULL) {ShowTab        Le (New Array ());            } else {var data = $.parsejson (Xmaqjson);        Showtable (data);    }} var lastIndex = undefined;            function Showtable (Xmaqjson) {$ ("#tt"). DataGrid ({idfield: "id", Fitcolumns:false, Title: "Project full-time safety management personnel", Singleselect:true, FrozenColumns: [[{field: ' id ', checkb            Ox:true}], columns: [[{field: ' Zrztid ', align: ' center ', width:0}, {field: ' Gcid ', hidden:true, align: ' center ', width:0}, {field: ' Gccode ', align: ' center ', width : 0}, {field: ' Zzid ', hidden:true, align: "center", width:0}, {field: ' Zzsj ', Alig N: "Center", width:0}, {field: ' XM ', title: ' Name ', width:130, sortable:true, align: ' center ', required : True, Editor: {type: ' Text '}}, {field: ' Aqsckhzh ', title: ' Safety Inspection Certificate number ', width:150, Sortable:true, align : ' Center ', editor: ' Text '}, {field: ' Lxdh ', title: ' Contact Phone ', width:100, sortable:true, align: ' center '  Editor: ' Text '}]], toolbar: [{text: ' Add ', Iconcls: ' Icon-add ', handler:function () {if (endediting ()) {$ (' #tt '). D Atagrid (' Appendrow ', {row: {ID: ', zrztid:id,gcid: ', Gccode: ',                            Zzid: ', ZZSJ: ', XM: ', Aqsckhzh: ',                        LXDH: '}}); if ($ (' #tt '). DataGrid (' GetRows ')! = undefined) {LastIndex = $ (' #tt '). DataGrid (' GetRows '). length-                        1; } $ (' #tt '). DataGrid (' SelectRow ', LastIndex). DataGrid (' BeginEdit ', l Astindex)}}}, '-', {text: ' delete ', iconcls: ' I                    Con-remove ', handler:function () {var row = $ (' #tt '). DataGrid (' getselected ');                        if (row) {var index = $ (' #tt '). DataGrid (' Getrowindex ', row); $ (' #tt '). DataGrid (' CancelEdit ', index). DataGrid (' DeleteRow ', index);                    LastIndex = undefined; }}}//, '-', {//text: ' Save ',//iconcls: ' Icon-save ',//Handler:function () {//if (endediting ()) {//$ (' #tt '). Datag RID (' acceptChanges ');//}//}//}, '-', {text : ' Reset ', iconcls: ' Icon-undo ', Handler:function () {$ (' #tt '). DataGrid (' R                    Ejectchanges ');                LastIndex = undefined; }}], Onclickrow:function (index) {if (LastIndex! = index) {if (Endediting ()) {$ (' #tt '). DataGrid (' SelectRow ', Index). DataGrid (' BeginEdit                            ', index);                        LastIndex = index; } ElSE {$ (' #tt '). DataGrid (' SelectRow ', lastIndex);        }                }            }        });    $ ("#tt"). DataGrid ("LoadData", Xmaqjson); } function endediting () {if (LastIndex = = undefined) {return true} if ($ (' #tt '). DataGrid (' Validaterow ', LA            Stindex) {var ed = $ (' #tt '). DataGrid (' Geteditor ', {index:lastindex,field: ' XM '});            var XM = $ (ed.target). Val ();            var ed1 = $ (' #tt '). DataGrid (' Geteditor ', {index:lastindex,field: ' Aqsckhzh '});            var Aqsckhzh = $ (ed1.target). Val (); if (XM! = ' && xm! = undefined && Aqsckhzh! = ' && aqsckhzh! = undefined) {$ (' #tt ')                . DataGrid (' EndEdit ', lastIndex);                LastIndex = undefined;            return true;                }else{Alert ("Project full-time safety management personnel" + (LASTINDEX+1) + "line" name "and" safety inspection "must be filled in");            return false;        }} else {return false;  }  }</script> 

jquery Easyui-datagrid Manually add a delete reset line

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.