Using the Tablednd plugin in Jqgrid

Source: Internet
Author: User
Tags jqgrid

First prepare jquery, Jqgrid, tablednd and other JS files.

TABLEDND recommends that you download the SRC package directly on GitHub to avoid unnecessary problems. Connection Address Https:// Note that you can refer to the applicable jquery version or else it will be problematic.

The TABLEDND plugin is used in Jqgrid to implement the drag-and-drop operation of the row in the form.

First in $ (document). Ready (function () {...}) Add the following code:

1 //jqgrid Form Dragging2$ ("#gridTable"). TABLEDND ({3Scrollamount:1,4Draghandle: ". Draghandle",5OnDrop:function(table, row) {6ID;7 getmkxh (id,uid);8             },9Onallowdrop:function(Draggedrow, row) {TenUID =$ (row). index (); One                 return true; A             } -});//End $ ("#gridTable"). Tablednd
View Code

Refer to the description in the Tablednd.js file for the specific attribute description. Here's the Draghandle, ". Draghandle" is the style configured in the JSP page.

I write it directly in the JSP page, not to the CSS file. The code is as follows: (ref. TABLEDND.CSS)

1 <style type= "Text/css" >2 . Draghandle{3 4}5 . Showdraghandle{6 Background-image:URL (images/updown2.gif);7 background-repeat:no-repeat;8 background-position:Center Right;9 cursor:Move;Ten} One </style>
View Code

The default draghandle is the ability to drag and drop the entire row, but sometimes that's not what we need. We may just want to drag and drop one or some of the cells to reach the dragging effect. Therefore, it is necessary to add some cells to a column in Jqgrid, adding the class attribute, whose value = ". Draghandle", in Jqgrid, where Colmodel is used to set the column properties, my configuration is as follows:

{name: ' CJR ', index: ' CJR ', autowidth:True, align: ' center ', classes: ' Draghandle '}

Classes can be configured with multiple values.

This enables drag-and-drop row functionality by dragging and dropping each row of the name= ' CJR ' column.

In Jqgrid's gridcomplete:function () {...}) Add the following code in the function:

$ ("#_empty", "#gridTable"). AddClass ("Nodrag nodrop"); // style                 $ ("#gridTable Tr:even '). addclass (' Alt ')");                 $ ("#gridTable"). Tabledndupdate (); // methods for updating the Jquery.tablednd.js plugin. 

To be more intuitive, you need to add some styles. is the. Showdraghandle in the code above, binding a hover function on each row.

$ ("#gridTable tr"). Hover (function() {                     $ (this. cells[6]). addclass (' Showdraghandle ' );                      function () {                         $ (this. cells[6]). Removeclass (' Showdraghandle ');                     }); 

This code must be written in Gridcomplete:function () {...}) Inside, writing in other places will be problematic.

The background is a simple serial number exchange. Also my Jqgrid form here is mapped to the Ztree tree menu.

Using the Tablednd plugin in Jqgrid

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: 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.