Use Struts2 and jquery Easyui to implement a simple CRUD system (iii)--check box for multiple-select Delete operations

Source: Internet
Author: User

Following the Jsp,json,easyui of the previous chapter of the successful conversion of database data into JSON format and then Easyui complete display (Retrieve), the next implementation and add and delete functions are also very handy.


The added function is the same, but the original form is written by Ejui to provide a form instead.


The deletion function needs to get the ID of the specific selection row.


<table id= "DG" title= "My Users" class= "Easyui-datagrid" style= "width:700px"; height:500px "url=" List_ej "toolbar=" #toolbar "rownumbers=" true "fitcolumns=" true "  ><thead><tr> <!--This notation is also possible <th field= "id" width= ">id</th><th field=" name "Width=" >name</th>< th field= "password" width= ">password</th>--><th field=" ck "checkbox=" true "></th><th data-options= "field: ' ID ', Width: ' 200px '" >id</th><th data-options= "field: ' Name ', Width: ' 200px '" > name</th><th data-options= "field: ' Password ', Width: ' 200px ', align: ' right '" >password</th></tr ></thead></table>

The entire DataGrid gets the ID of the selected row.

var row = $ (' #dg '). DataGrid (' getselected '); var id = row.id;
Why would I know? How to learn this method? --Look at the API.

This is also true of multiple choices, except that an array is returned. After getting the ID, the next thing you can do is to give struts a handle.


Well, next so much data, if one is deleted when the egg hurts, then we need to check box this delete. How simple it is to add a check box.

<table id= "DG" title= "My Users" class= "Easyui-datagrid" style= "width:700px"; height:500px "url=" List_ej "toolbar=" #toolbar "rownumbers=" true "fitcolumns=" true "  Singleselect =" false " Checkbox= "true" ><thead><tr><!--This notation is also possible <th field= "id" width= ">id</th><th" field= "name" width= ">name</th><th field=" password "width=" >password</th>--><th field= "CK" checkbox= "true" ></th><th data-options= "field: ' ID ', Width: ' 200px '" >id</th><th data-options= "field: ' Name ', Width: ' 200px '" >name</th><th data-options= "field: ' Password ', Width: ' 200px ' , align: ' right ' >password</th></tr></thead></table>

Singleselect = "false" checkbox= "true" is optional for false,checkbox to use.


Next in JS:

        Returns the selected row and then integrates the object array in fact as        var row = $ (' #dg '). DataGrid (' Getselections ');        var i = 0;        var string = "";            for (i;i<row.length;i++) {string + = Row[i].id;            if (I < row.length-1) {string + = ', ';            }else{break; }        }
into a character array, and finally to the action side, directly using:

St.executeupdate ("Delete from user ' where UserID in (" +id+ ")");


Once deleted, the DataGrid is refreshed.

if (row.length>0) {$.messager.confirm (' confirm ', ' OK delete user? ', function (r) {if (R) {$.post (' DeleteUser ', {id:string}, F Unction (Result) {$ (' #dg '). DataGrid (' Reload ');});});

and edit the user's words can only be based on the specific user to edit, so multiple selection of the situation directly alert, can not select more than one data.


Complete JS in the code of the delete function:

function Destroyuser () {        //returns the selected row and then integrates the object array in fact as        var row = $ (' #dg '). DataGrid (' Getselections ');        var i = 0;        var string = "";        for (i;i<row.length;i++) {        string + = Row[i].id;        if (I < row.length-1) {        string + = ', ';        } else{break        ;        }        }        alert (string);//var row = $ (' #dg '). DataGrid (' getselected ');//alert (row.id); if (row.length== 0) {alert (select row to delete);} if (row.length>0) {$.messager.confirm (' confirm ', ' OK delete user? ', function (r) {if (R) {$.post (' DeleteUser ', {id:string}, F Unction (Result) {$ (' #dg '). DataGrid (' Reload ');});}});}

$.post (' DeleteUser ', {id:string here) the entire string as the ID parameter of the value to the DeleteUser this URL, through struts jump after the corresponding data deletion, complete the function.



Use Struts2 and jquery Easyui to implement a simple CRUD system (iii)--check box for multiple-select Delete operations

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.