Ligergrid Ajax Paging Get sort details

Source: Internet
Author: User
Tags date1

Just started to use Ligergrid for sorting the headache, find, up and down the background can not accurately get the foreground lookup control inside the value of the API, there is no detailed explanation

Finally on the internet for a long time feeling is not very full of information, now put this together to make a note

First, the last fruit chart

To do paging generally need to note that the page size, the current page, sort fields, sort type (flashback or order), query criteria, so here write a public method to return the required sorting data and query conditions under the total data bar number

This is a method of handling the call.

<summary>///Get one page of log data///</summary>//<param name= "Allcount" ></param>  <param name= "pageSize" ></param>//<param name= "PageIndex" ></param>// <param name= "title" ></param>//<param name= "type" ></param>//<param name= "da Te1 "></param>//<param name=" Date2 "></param>//<param name=" UserName "></pa ram>//<param name= "by" ></param>///<returns></returns> public Lis T<solution.hpk.corearea.model.log> Getpagerdata (out long allcount, int pageSize = $, int pageIndex = 1, String titl            E = "", String type = "", String date1 = "", String date2 = "", String userName = "", String by = "") {            StringBuilder where = new StringBuilder ();            list<sqlparameter> parlist = new list<sqlparameter> (); if (!striNg. IsNullOrEmpty (title)) {where.                Append ("and CHARINDEX (@Title, Title) >0");            Parlist.add (New SqlParameter ("@Title", SqlDbType.NVarChar) {Value = Title}); } if (!string. IsNullOrEmpty (type)) {where.                Append ("and [email protected]");            Parlist.add (New SqlParameter ("@Type", SqlDbType.NVarChar) {Value = Type}); } if (date1. Isdatetime ()) {where.                Append ("and writetime>[email protected]"); Parlist.add (New SqlParameter ("@Date1", sqldbtype.datetime) {Value = Date1. ToDateTime ().            ToString ("Yyyy-mm-dd 00:00:00")}); } if (Date2. Isdatetime ()) {where.                Append ("and writetime<[email protected]"); Parlist.add (New SqlParameter ("@Date2", sqldbtype.datetime) {Value = Date2. ToDateTime (). AddDays (1).            ToString ("Yyyy-mm-dd 00:00:00")});       }     if (!username.isnullorempty ()) {where.            Append ("and UserName like '%" + UserName + "% '"); } String sql = SOLUTION.HPK.COREAREA.UTILITY.DATABASE.DBHELPER.GETPAERSQL ("Log", "Id,title,type,writetime,useri D,username,ipaddress,url,contents,others,oldxml,newxml ", where.            ToString (), PageSize, PageIndex, out Allcount, Parlist.toarray ());            SqlDataReader dataReader = Solution.HPK.CoreArea.Utility.DataBase.DBHelper.ExecSelect (sql, Parlist.toarray ());            list<solution.hpk.corearea.model.log> List = datareadertolist (DataReader);            Datareader.close ();        return List; }


There's a SOLUTION.HPK.COREAREA.UTILITY.DATABASE.DBHELPER.GETPAERSQL method, which is the common method used.

<summary>//Get paged SQL///</summary>//<param name= "SQL" ></param> <returns></returns> public static string Getpaersql (string table, String fileds, string where, St Ring order, int size, int number, out long count, sqlparameter[] param = null) {string where1 = string.            Empty; if (where.            IsNullOrEmpty ()) {where1 = ""; } else {where1 = where.                Trim (); if (where1. StartsWith ("and", Stringcomparison.currentcultureignorecase)) {where1 = Where1.                Substring (3); }} String where2 = Where1. IsNullOrEmpty ()?            "": "where" + where1; String sql = string.            Format ("Select {0},row_number () over (ORDER by {1}) ' as Pagerautorownumber from {2} {3}", Fileds, ORDER, table, Where2); String count1 = GetFieldValue (string. Format ("seLect Count (*) from {0} {1} ", table, Where2), param);            Long I; Count = Count1. Islong (out i)?            i:0;            StringBuilder SQL1 = new StringBuilder (); SQL1. AppendFormat ("Select {0} from (", Fileds. IsNullOrEmpty ()?            "*": fileds); SQL1.            Append (SQL); SQL1.            AppendFormat (") as pagertemptable"); if (count > Size) {//(page 1) * Page size +1 an pages * page size SQL1.            AppendFormat ("where Pagerautorownumber between {0} and {1}", (number-1) * size + 1, number * size); } return SQL1.        ToString (); }


This method can be used directly, the specific parameters can be understood at a glance

The core method of retrieving data in the background is the following is the design of the foreground UI

var maingrid =$ ("#mainGrid"). Ligergrid ({columns: [{display: ' Serial number ', Name: ' Index ', align: ' Center ', width:40}, {display: ' title ', Name: ' title ', align: ' Left '}, {display: ' Category ', name : ' Type ', align: ' center ', width:140}, {display: ' IP address ', Name: ' IPAddress ', align: ' center ', width:140 }, {display: ' Creation Date ', Name: ' Writetime ', align: ' center ', width:140}, {display: ' operator ', NA Me: ' UserName ', align: ' center ', width:120},], usepager:true, Height: ' 99% ', Checkbox:true, rownumbers : false, Pagesizeoptions: [+,], pagesize:16, page:1, url: "Handler/getpage.ashx",                Sortname: ' Writetime ', SortOrder: ' Desc ', Ontofirst:ontofirst, Ontoprev:ontoprev, Ontonext:ontonext, ontolast:ontolast});


Ligergrid This method does not understand can refer to the API, focus on the need to pay attention to

URL attribute is a path used for AJAX requests

Sortname

SortOrder These 2 attributes are the default according to which field is sorted, if you do not write to the background to assign default values, it is recommended to write directly in the foreground

Ontofirst,ontoprev,ontonext,ontolast home, Prev, Next, last, these events must be handled manually in the foreground, otherwise the interface will not be able to send the query to the background

Implementation is also very simple, write a default method of assigning Ajax parameters in front of the 4 call that method just fine

Set the Ajax parameter        function setparms () {            maingrid.setparm ("title", $ ("#txtTitle"). Val ());            Maingrid.setparm ("Type", $ ("#txtType"). val () = = "= = ALL = ="? "": $ ("#txtType"). Val ());            Maingrid.setparm ("UserName", $ ("#txtUserName"). Val ());            Maingrid.setparm ("StartDate", $ ("#txtStartDate"). Val ());            Maingrid.setparm ("EndDate", $ ("#txtEndDate"). Val ());        


Home            function Ontofirst () {                setparms ();            }            Last            function Ontolast () {                setparms ();            }            Prev            function Ontoprev () {                setparms ();            }            Next page            function Ontonext () {                setparms ();            }


When you click on the Query button, you need to pay attention

Query button            $ ("#btnSearch"). Ligerbutton ({                click:function () {                    //Reset query pages, starting from the first page                    maingrid.set ({page: 1, newpage:1});                    Set ajax parameter                    setparms ();                    Re                    -Request Maingrid.loaddata (Maingrid.url);                }            });


The above sentence Maingrid.set ({page:1, newpage:1});

It's been a long time.

Mainly to solve a problem such as the current page is 3 pages total page for 8 pages If you click Find without Maingrid.set ({page:1, newpage:1});

He will end up on page 3rd, so there will be problems, general click-to-find is initially the first page

The front desk is so much better, the following is the backstage

LIGERGUID Ajax By default is the post submission method, and the default is the current page, page size, sort fields, sort the type of the past directly accept it.

The current page, int, page            = context. request.form["Page"]. ToInt32 ();            Page size            int pageSize = context. request.form["PageSize"]. ToInt32 ();            Sort field            String sortname = context. request.form["Sortname"];            Sort order            String sortOrder = context. request.form["SortOrder"];


And get the front bed. Query parameter returns a JSON object such as {total:xxxx,rows:[]} The format of total and Rows must exist otherwise ligerguid

Such as

public void ProcessRequest (HttpContext context) {context.            Response.ContentType = "Text/plain"; The current page, int, page = context. request.form["Page"].            ToInt32 (); Page size int pageSize = context. request.form["PageSize"].            ToInt32 (); Sort Field String Sortname = Context.            request.form["Sortname"]; Sort order String SortOrder = context.            request.form["SortOrder"]; Other custom ajax Parameters string title = Context.            request.form["title"]; String type = context.            request.form["type"]; String userName = context.            request.form["UserName"]; String StartDate = context.            request.form["StartDate"]; String endDate = context.            request.form["EndDate"];            LOGBLL LOGBLL = new LOGBLL ();            The total number of query data long allcount; Paging lookup data var loglist = Logbll.getpagerdata (out allcount, PageSize, page, title, type, StartDate, EndDate, UserN Ame, sortName + "" + SortOrder);            Returns the JSON array list<string> jsonlist = new list<string> ();                for (int i = 0; i < Loglist.count; i++) {var log = Loglist[i]; Jsonlist.add ("{\" id\ ": \" "+ log.id +" \ ", \" index\ ": \" "+ ((i + 1) + (page-1) * pageSize) +" \ ", \" title\ ": \" "+ Log. Title + "\", \ "type\": \ "" + Log. Type + "\", \ "ipaddress\": \ "" + Log. IPAddress + "\", \ "writetime\": \ "" + Log. Writetime.tostring ("Yyyy-mm-dd HH:mm:ss") + "\", \ "username\": \ "" + Log.            UserName + "\"} "); } context. Response.Write ("{\" total\ ": \" "+ Allcount +" \ ", \" rows\ ": [" + String.        Join (",", jsonlist) + "]}"); }


All right, that's it. Fully compliant with paging, lookup, field sorting, this code is not missing a direct use

Ligergrid Ajax Paging Get sort details

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.