Using jQuery to sort tables by dragging

Source: Internet
Author: User

The principle is to use the mousedown, mouseover, and mouseup events to drag and use Ajax to save the results.

The JS Code is as follows:

MoveStart =; curTr; tarTr; $ ("# tableDataList "). find ("tr "). find ("td: not (: last )"). mousedown (==$ ("td "). addClass ("highlightTd" "pointer" $ ("# tableDataList "). find ("tr "). mouseover (ch = "input [type = 'checkbox']" (moveStart = & curTr. find (ch ). attr ("subid ")! = $ (). Find (ch ). attr ("subid" (curTr. offset (). top> $ (). offset (). top) {tarTr =$ ($ ("# tableDataList "). find ("tr "). mouseup (moveStart = "td "). removeClass ("highlightTd" "pointer" subjectIds = ""; $ ("# tableDataList "). find ("input [type = 'checkbox'] [id! = 'Checkall'] "). each (+ = $ (). attr (" subId ") +", "(subjectIds! = "" POST "" # {ChangeSubjectsSortUrl} "" subjectIds = "+ subjectIds. substr (0, subjectIds. length-1), success: (data = "OK" I = 0 "# tableDataList "). find ("tr: not (: first )"). each (++ ). find ("td: eq (3)" developer.html (I); </script>View Code

The HTML code is as follows (Note: The Framework automatically sets <! -- BEGIN list --> and <! -- END list --> ):

Question preview questionnaire add question name question type question sequence question score operation # {edu_QnSubject.Title} modify and deleteView Code

The Controller code is as follows:

ChangeSubjectsSort (subjectIds = ctx. post ([] subjectIdArray = subjectIds. split (I =; I <subjectIdArray. length; I ++ = edu_QnSubjectService.findById <Edu_QnSubject> (= I + = edu_QnSubjectService.update (qnSubject );View Code

(Static images do not show dynamic effects. Here we will show you ):

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.