Example 1 of jqGrid implementation in json format: jqgridjson format

Source: Internet
Author: User
Tags jqgrid

Example 1 of jqGrid implementation in json format: jqgridjson format

QGrid is a jQuery plug-in used to display grid data. By using jqGrid, you can easily implement ajax asynchronous communication between front-end pages and background data. Comprehensive documentation, its official website: http://www.trirand.com.

 

Js Introduction

 <!-- The jQuery library is a prerequisite for all jqSuite products -->    <script type="text/ecmascript" src="jqgrid/js/jquery-2.1.1.min"></script>     <!-- We support more than 40 localizations -->    <script type="text/ecmascript" src="jqgrid/js/i18n/grid.locale-en.js"></script>    <!-- This is the Javascript file of jqGrid -->       <script type="text/ecmascript" src="jqgrid/js/jquery.jqGrid.min.js"></script>    <!-- This is the localization file of the grid controlling messages, labels, etc.    <!-- A link to a jQuery UI ThemeRoller theme, more than 22 built-in and many more custom --><link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.4/css/bootstrap.min.css">     <!-- The link to the CSS that the grid needs -->    <link rel="stylesheet" type="text/css" media="screen" href="../../../css/trirand/ui.jqgrid-bootstrap.css" /><script>$.jgrid.defaults.width = 780;</script><script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.4/js/bootstrap.min.js"></script>    <meta charset="utf-8" />

  

Front-end html code

<div style="margin-left:20px">    <table id="jqGrid"></table>    <div id="jqGridPager"></div></div>

 

Jqgrid javascript code

<Script type = "text/javascript"> $ (document ). ready (function () {$ ("# jqGrid "). jqGrid ({url: 'data2. json ', mtype: "GET", datatype: "json", // type returned by the request data. Optional json, xml, txt colModel: [{label: 'orderid', name: 'orderid', key: true, width: 75}, {label: 'customer id ', name: 'mermerid', width: 150}, {label: 'order date', name: 'orderdate', width: 150}, {label: 'freight ', name: 'freight ', width: 150}, {label: 'ship name', Name: 'shipname', width: 150}], viewrecords: true, height: 250, rowNum: 20, pager: "# jqGridPager"}) ;}); </script>

  

The json format introduced by url is as follows:

{"rows":[{"OrderID":"1","CustomerID":"WILMK","OrderDate":"1996-07-04 00:00:00","Freight":"32.3800","ShipName":"Vins et alcools Chevalier"},{"OrderID":"2","CustomerID":"TRADH","OrderDate":"1996-07-05 00:00:00","Freight":"11.6100","ShipName":null},{"OrderID":"3","CustomerID":"HANAR","OrderDate":"1996-07-08 00:00:00","Freight":"65.8300","ShipName":"Hanari Carnes"},{"OrderID":"4","CustomerID":"VICTE","OrderDate":"1996-07-08 00:00:00","Freight":"41.3400","ShipName":"Victuailles en stock"},{"OrderID":"5","CustomerID":"SUPRD","OrderDate":"1996-07-09 00:00:00","Freight":"51.3000","ShipName":null},{"OrderID":"6","CustomerID":"HANAR","OrderDate":"1996-07-10 00:00:00","Freight":"58.1700","ShipName":"Hanari Carnes"},{"OrderID":"7","CustomerID":"CHOPS","OrderDate":"1996-07-11 00:00:00","Freight":"22.9800","ShipName":"Chop-suey Chinese"},{"OrderID":"8","CustomerID":"RICSU","OrderDate":"1996-07-12 00:00:00","Freight":"148.3300","ShipName":"Richter Supermarkt"},{"OrderID":"9","CustomerID":"WELLI","OrderDate":"1996-07-15 00:00:00","Freight":"13.9700","ShipName":"Wellington Importadora"},{"OrderID":"10","CustomerID":"HILAA","OrderDate":"1996-07-16 00:00:00","Freight":"81.9100","ShipName":null},{"OrderID":"11","CustomerID":"ERNSH","OrderDate":"1996-07-17 00:00:00","Freight":"140.5100","ShipName":"Ernst Handel"},{"OrderID":"12","CustomerID":"CENTC","OrderDate":"1996-07-18 00:00:00","Freight":"3.2500","ShipName":"Centro comercial Moctezuma"},{"OrderID":"13","CustomerID":"OLDWO","OrderDate":"1996-07-19 00:00:00","Freight":"55.0900","ShipName":null},{"OrderID":"14","CustomerID":"QUEDE","OrderDate":"1996-07-19 00:00:00","Freight":"3.0500","ShipName":null},{"OrderID":"15","CustomerID":"RATTC","OrderDate":"1996-07-22 00:00:00","Freight":"48.2900","ShipName":"Rattlesnake Canyon Grocery"},{"OrderID":"16","CustomerID":"ERNSH","OrderDate":"1996-07-23 00:00:00","Freight":"146.0600","ShipName":"Ernst Handel"},{"OrderID":"17","CustomerID":"FOLKO","OrderDate":"1996-07-24 00:00:00","Freight":"3.6700","ShipName":null},{"OrderID":"18","CustomerID":"BLONP","OrderDate":"1996-07-25 00:00:00","Freight":"55.2800","ShipName":null},{"OrderID":"19","CustomerID":"WARTH","OrderDate":"1996-07-26 00:00:00","Freight":"25.7300","ShipName":"Wartian Herkku"},{"OrderID":"20","CustomerID":"FRANK","OrderDate":"1996-07-29 00:00:00","Freight":"208.5800","ShipName":"Frankenversand"}]}

 

With the above code, you can simply implement the effect of a table.

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.