ajax| Pagination | sorting | data
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:
Http://www.knowsky.com
<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>
Data supply page:
<%@ Page language= "C #" autoeventwireup= "true" inherits= "HFSoft.MVC.DataViewContext"%>
<%@ Import namespace= "Northwind.entities"%>
<%
HFSoft.MVC.IDataViewContext DataView = (HFSoft.MVC.IDataViewContext) this;
%>
<table width= "100%" >
<% if (DataView. PageCount >0) {%>
<tr>
<TD colspan= "7" style= "height:20px" >
<a href= "#" pageindex= "0" > Home </a>
<a href= "#" pageindex= "<% =dataview. Prevpage%> "> Prev </a>
<a href= "#" pageindex= "<% =dataview. NextPage%> "> next page </a>
<a href= "#" pageindex= "<% =dataview. Pagecount-1%> "> Last </a>
Current <%=dataview. Pageindex+1%> page/Total <%=dataview. PageCount%> Page
</td>
</tr>
<%}%>
<tr>
<TD style= "width:100px; Font-weight:bold; Background-color:activeborder; " >
<a href= "#" orderfield= "<%=dataview. GetOrderInfo ("CompanyName")%> ">CustomerName</a></td>
<TD style= "width:100px; Font-weight:bold; Background-color:activeborder; " >
<a href= "#" orderfield= "<%=dataview. GetOrderInfo ("Employees.EmployeeID")%> ">EmployeeName</a></td>
<TD style= "width:100px; Font-weight:bold; Background-color:activeborder; " >
<a href= "#" orderfield= "<%=dataview. GetOrderInfo ("OrderDate")%> ">OrderDate</a></td>
<TD style= "width:100px; Font-weight:bold; Background-color:activeborder; " >
<a href= "#" orderfield= "<%=dataview. GetOrderInfo ("RequiredDate")%> ">RequireDate</a></td>
<TD style= "width:100px; Font-weight:bold; Background-color:activeborder; " >
Shipaddress</td>
<TD style= "width:100px; Font-weight:bold; Background-color:activeborder; " >
Shipcity</td>
<TD style= "width:100px; Font-weight:bold; Background-color:activeborder; " >
Sipcountry</td>
</tr>
<%foreach (Order_v item in DataView.) Dataitems)
{%>
<tr>
<TD style= "width:100px" ><%=dataview. Tovalue (item. CustomerName)%>
</td>
<TD style= "width:100px" ><%=dataview. Tovalue (item. EmployeeName)%>
</td>
<TD style= "width:100px" ><%=dataview. Tovalue (item. OrderDate, "{0:d}")%>
</td>
<TD style= "width:100px" ><%=dataview. Tovalue (item. RequiredDate, "{0:d}")%>
</td>
<TD style= "width:100px" ><%=dataview. Tovalue (item. shipaddress)%>
</td>
<TD style= "width:100px" ><%=dataview. Tovalue (item. ShipCity)%>
</td>
<TD style= "width:100px" ><% =dataview. Tovalue (item. ShipCountry)%>
</td>
</tr>
<%}%>
</table>
Data provides page-related controller code:
[HFSoft.MVC.FormMapper ("~/frmorderview.aspx")]
public void Orderview ()
{
HFSoft.MVC.IDataViewContext ViewContext = (HFSoft.MVC.IDataViewContext) this. Formcontext;
Iexpression exp;
fieldadapter[] by = null;
Ordersearch search = ViewContext. Bindobject<ordersearch> ();
Exp = Search. GetExpression ();
if (ViewContext. OrderField!= null && viewcontext. OrderField!= String. Empty)
{
By-by = new Fieldadapter[]{new Fieldadapter (ViewContext. OrderField, NULL)};
}
Region Region = new Region (viewcontext. PageIndex *, ViewContext. PageIndex * 10+10);
ViewContext. Dataitems = exp. List<order_v> (region, by);
ViewContext. PageSize = 10;
ViewContext. RecordCount = exp. Countof<order_v> ();
}
Download routine code and foot source: Http://www.cnblogs.com/Files/henryfan/AjaxSearchDataSample.rar