Use jquery to facilitate data query, sorting, and paging based on Ajax

Source: Internet
Author: User
Tags sort

JavaScript was rarely used to implement page functionality, but the idea changed when 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.

First look at the implementation of the foot code:

/** Apply scripting Rules:

Reference script: jquery script and jquery form plug-in script

The Id:viewform of the form

Id:listview of the div that displays the data

Pagination Button HTML property: pageindex= "1"

Sort button HTML attribute: orderfield= "EmployeeID desc";

Id,name:orderfield of the input of the sort field of the extraction effect

Submit Id,name:pageindex for paging index input

**/

function oninitpaging ()

{

$ ("#listview"). Find ("[@orderfield]"). each (function (i)

{

var OrderValue = $ (this). attr ("OrderField");

$ (this). Click (Function ()

{

$ ("#orderfield"). Val (OrderValue);

Onsubmitpage ();

}

);

}

);

$ ("#listview"). Find ("[@pageindex]"). each (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 used 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 and you just need to follow the rules that are 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= "cellpadding=" "0" cellspacing= "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= "WIDTH:63PX; 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" button "type=" ... "value=

<TD style= "WIDTH:63PX; 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" button "type=" ... "value=

</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>

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.