Jquery+ajax implementation of data query, sorting and paging function _jquery

Source: Internet
Author: User

It's very rare to use JavaScript to implement page functionality in the first place, but the idea has changed since you learned about jquery; With such a script component you can easily and HTML isolate it when writing scripts, which makes it easier to write highly reusable scripts. The following is a reusable script that describes the AJAX-based data query, sorting, and paging capabilities written in the learning jquery process, as long as the scripting files are introduced by following some rules of the script to facilitate the functionality described above.
Look at the code that implements the functionality first:

/** applying scripting rules: Referencing scripts: jquery script and jquery form plug-in script form Id:viewform page id:listview paging button htm displaying data div
L attribute: pageindex= "1" Sort button HTML attribute: orderfield= "EmployeeID desc"; Effect sort field input Id,name:orderfield submit Paging index input Id,name:pageindex **/function oninitpaging () {$ ("#listview"). Find ("[@ OrderField] ""). each (function (i) {var ordervalue = $ (this). attr ("OrderField"), $ (this). Click (function () {$ ("#
OrderField "). Val (OrderValue);
Onsubmitpage ();
}
);
}
); $ ("#listview"). Find ("[@pageindex]"). each (the function (i) {var pivalue = $ (this). attr ("pageindex"), $ (this). Click (
Function () {$ ("#pageindex"). Val (Pivalue); Onsubmitpage ();});
}
); function Onsubmitpage () {var options = {success:function submitsuccess (data) {$ ("#listview"). HTML (data); oninitpaging
();
}
};
$ (' #viewform '). Ajaxsubmit (options);
$ (document). Ready (function () {$ ("#search"). Click (function () {$ ("#pageindex"). Val (' 0 '); onsubmitpage ()});
Onsubmitpage ();
}
); 

Constraint rules skillfully use HTML custom attributes, the above code describes the query, sorting and paging of the AJAX submission processing. You don't need to write any scripting code when you're writing HTML just by following the rules described, and you just need to add the script to the page:

<script src=jquery-latest.js></script> <script src=form.js></script> <script src= calendar.js></script> <script src=calendar-setup.js></script> <script src= "lang/ Calendar-en.js "></script> <script src=pagination.js></script> <form id=" Viewform "method=" Post "action=" frmorderview.aspx "> <input id=" OrderField "name=" OrderField "type=" hidden "value=" "/> < Input id= "pageindex" name= "pageindex" type= "hidden" value = "0"/> <table border= "0" cellpadding= "0" cellspacing= "0 "Style=" width:100%; height:100% "> <tr> <td valign=" Top "align=" left "> <table width=" 0 "cellpadding=" 0 " > <tr> <td style= "WIDTH:63PX; height:17px; Background-color:gainsboro; " > companyname</td> <td style= "WIDTH:114PX; height:17px; " > <input id= "Text1" Name= "CompanyName" type= "text"/></td> <td "style="; height:17px; Background-color:gainsboro;"> Shipcity</td> <td style=" WIDTH:126PX; height:17px; " > <input id= "Text2" name= "shipcity" type= "text"/></td> </tr> <tr> <td style= "WIDTH:63PX; height:14px; Background-color:gainsboro; " > orderdate</td> <td style= "width:240px; height:14px align= "Left" > <input id= "Text3" name= "Orderdate_begin" type= "text"/> <input id= "Button1" datefield= "Text3" "type=" button "value=" ... "/></td> <td" style=; height:14px; Background-color:gainsboro; " > </td> <td style= "width:240px; Height:14px "align=" left "> <input id=" TEXT4 "type=" text "name=" Orderdate_end "/> <input id=" Button2 " datefield= "TEXT4" "type=" button "value=" ... "/></td> </tr> <tr> <td style=" height:50px "align="
Left "colspan=" 4 "> <input id=" Search "type=" button "value=" Search "/></td> </tr> </table> </td> </tr> <tr> <td height= "99%" > <div id="ListView" ></div> </td> </tr> </table> </form>
 

The above is about how to use jquery to facilitate the implementation of data query, sorting and paging based on Ajax ideas, I hope this article can bring inspiration and inspiration.

Related Article

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.