Jqgrid has another useful function: jqgridimport & jqgridexport

Source: Internet
Author: User
Tags jqgrid

Today, we can see a good example of using jqgrid in ASP. net mvc razor. This article is just learning a function in this example. For more information about jqgridimport, see here.

Jqgrid also has a very useful function that can import and export jqgrid configurations, which means: Use the C # Anonymous class and jsonresult (ASP. net mvc) with C #CodeInstead of using JS Code, jqgrid is generated. Many people are afraid of writing JavaScript code. They would rather write two lines of C # code than one line of JS Code, this function is a good news for those who do not want to write Javascript. It's not too early. Let's go directly to the content.

The view in razor is written in this way.

@ {Layout = NULL ;}<! Doctype HTML> 

Here I will describe the several options used in the Code. For more information, see the documentation here.

Imptype: jqgrid imports the "template" (Please allow me to give it such a nondescribable name, the same below) in JSON format. Of course, it can also be in XML format, however, I don't think XML is often used for further research.

Impurl: jqgrid imports the "template" from this URL.

Mtype: This is simple. It is the HTTP method for obtaining the imported "template.

Jsongrid: where to obtain the JSON-format import "template" configuration options. Here, I will explain a little bit about how to obtain an object from impurl, in jsongrid, config refers to the property of the obtained object, which is the configuration option. After reading the background code, it is easier to understand.

OK. Now let's see what the background code looks like:

Public actionresult import () {var configs = new {url = "/user/Index", datatype = "JSON", mtype = "get ", colnames = new [] {"primary key", "name", "Mailbox"}, colmodel = new [] {New {name = "ID", Index = "ID ", width = 200, hidden = true, align = "Left"}, new {name = "name", Index = "name", width = 200, hidden = false, align = "Left"}, new {name = "mail", Index = "mail", width = 200, hidden = false, align = "Left "}}, sortname = "name", sortorder = "ASC", rownum = 10, rowlist = new [] {10, 15, 20}, pager = "# pager", viewrecords = true, height = "Auto", width = "Auto"}; return JSON (New {configs = configs}, jsonrequestbehavior. allowget );}

The preceding action provides the service for importing "template" configuration options. Assume that your view name is importdemo. for cshtml, the code used for the entire request should also include an action for MVC to open the View:

 
Public actionresult importdemo () {return view ();}

In the end, as long as you enable the importdemo view, the "template" will be automatically obtained from the import service"

Source code download

I am very sorry to attach the official document. I said last night that there was no official document. I found it this morning.

Importing

This method reads the grid configuration according to the rules in options and constructs the grid. when constructing the grid for first time it is possible to pass data to it again with the configuration. this is done with jqgirdimport

Jquery("# Grid_id").Jqgridimport(Options);

Where

    • grid_id is the ID of the table element where the grid shocould be constructed
    • options is array of pair name: value to set different configuration listed bellow
Option type description default
imptype string determines the type of import can be one of the following values XML, JSON, xmlstring, jsonstring XML
impstring string in case of xmlstring or jsonstring this shoshould be set
impurl string valid URL to the configuration when XML or JSON. the data is obtained via Ajax request
mtype string determines the type of request. can be get or post Get
impdata Object additional data that can be passed to the URL in pair name: value Empty object {}
xmlgrid Object describes from where to read the xml configuration and from where the data if any. the option config describes the configuration tag. the option Data describes the data tag config: "roots> grid",
data: "roots> rows"
jsongrid Object describes from where to read the JSON configuration and from where the data if any. the option config describes the configuration tag. the option Data describes the data tag config: "Grid",
data: "data"
Ajaxoptions Object Additional options which can be passed to the Ajax request Empty object {}
Events

There is only one event which can be called in jqgridimport.

event description
importcomplete this event is called after the successfully import and when the grid is constructed. to this event we pas the request from server. use this event to set additional parameters in the grid or to construct the navigator

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.