URL:http://www.trirand.com/blog/?page_id=4

1. Data returned from the server can be in XML or JSON

XML Syntax:
<?xml version ="1.0" encoding="utf-8"?>
<rows>
<page> </page>
<total> </total>
<records> </records> (new tag)
<row id = “unique_rowid”>
<cell> cellcontent </cell>
<cell> <![CDATA[<font color=”red”>cell</font> content]]> </cell>

</row>

</rows>

JSON Syntax:

{ total: xxx, page: yyy, records: zzz, rows: [
{id:”1″,cell:[”Row 1:1″,”Row 1:2″,”Row 1:3″,”Row 1:4″]},
{id:”2″,cell:[”Row 2:1″,”Row 2:2″,”Row 2:3″,”Row 2:4″]},
{id:”3″,cell:[”Row 3:1″,”Row 3:2″,”Row 3:3″,”Row 3:4″]},

]}

In page tag server must return the number of the requested page.
In total tag server must return the total pages of the query.
In records tag server can return the total records from the query.
In cell tag is the actual data. Note that CDATA can be used. This way we can add images, links and check boxes.

Actually the cell data in the grid is inserted as html and not as text.

In PHP script use the following code for page header (when using xml):

<?php
if ( stristr($_SERVER["HTTP_ACCEPT"],"application/xhtml+xml") ) {
header("Content-type: application/xhtml+xml"); } else {
header("Content-type: text/xml");
}
echo("<?xml version=/"1.0/" encoding=/"utf-8/"?>/n");
?>

2. The selector in the html document must be a table element of class “scroll”. Example:

<table id= "table_id" class="scroll" cellpadding="0" cellspacing="0">
</table>

3. Parameters passed to the server url (you must use a get method to obtain the values) are:
page - the requested page;
rows - the number of the requested rows that server must return;
sidx - the name (or number) of the column in the ORDER BY clause;
sord - way in which the column must be sorted - asc (ascending) or desc (descending);

4. Parameters used when constucting the grid. Example:

var mygrid = $(”#table_id”).jqGrid( {
url: “myurl.php”,
height: 150,
page: 1,
colNames: [”colname1″,”colname2″],
colModel: [
{index : ‘col1′, width : 80, sortable : true, align: ‘left’},
{index : ‘col’, width : 80, sortable : true, align: ‘left’}
],
rowNum: 20,
rowList: [20,30,40,50],
pager: $(”#page_selector_id”),
sortorder: “asc”,
sortname: “”,
altRows: true,
sortascimg : “sort_asc.gif”,
sortdescimg : “sort_desc.gif”,
firstimg: “first.gif”,
previmg: “prev.gif”,
nextimg: “next.gif”,
lastimg: “last.gif”,
onSelectRow: function (iRow) { …},
onSortCol: function (idx,iCol){ …},
ondblClickRow: function (iRow) { … }
});

Description of the parameters:

url: (mandatory) - the url where the XML file resides or is constructed with SQL.
height: (optional) - the heght of the grid in pixels. Default 150.
page: (optional) - the requested page number. Default 1.
colNames: (mandatory) - array which describes the column names in the grid
colModel: (mandatory) - array which describes the parameters of the columns. The parameters are:

  • name: (optional) - the index name which is used when sorting the data. Alias name can be used - i.e mytable.mycol. If this parameter is not set a unique number is assign in the order in which apper in the array - i.e 1,2… .
  • width: (mandatory) - the initial width of the column in pixels. Note that the width of the grid is sum of all columns width + 20 pixels for the scrolling.
  • sortable: (optional) describes if the column can be sorted. Valid values are true or false. Default is true.
  • align: (optional) - This attribute specifies the horizontal alignment of the element. Posible values are: left, center, right. Default is left.
  • sorttype: (optional) - This attribute describes the type of the field. This is only used if datatype option is set to “local”, or when load at once method is used. The possible values are: int, float, date, text.

rowNum: (optional) the number of rows that must be returned from the server (query). Default is 20.
rowList: (optional) if set this parameter construct a select box element in the pager in wich the user can change the number of the visible rows. Default is empty array.
pager: (optional) this parameter describes the pager. This must be a valid html element. Example: $(”#mypager_id”). If the element is of class “scroll”, then the width is equal to the grid.
sortorder: (optional) sets the sorting order. Default asc (ascending)
sortname: (optional) sets the initial sorting column. Can be a name or number. Default is empty string.
altRows: (optional) set a zebra like table. Default true
sortascimg : and sortdescimg : (optional) these parameters are liks to image url which are used when the user sort a column.
firstimg: , previmg: , nextimg: , lastimg: (optional) these parameters are liks to image url which are used in the pager.
onSelectRow: (optional) raised immideatly after row was clicked. The input parameter of the function is the row_id. Default null.
onSortCol: (optional) raised immideatly after sortable column was clicked and before sorting the data. The input parameters of the function are the index name and column index. Default null.
ondblClickRow: (optional) raised immideatly after row was double clicked. The input parameter of the function is the row_id. Default null.
datatype: (optional). Default “xml”. Possible values “xml” or “json” or “local”. Set this option according to data type returned from the server. If set to “local” the grid expected to load data local via array.
width: (optional) Default: none. If this option is not set, the width of the grid is a sum of the width’s of the columns defined in the column model + 20 pixels. If this option is set the width of each column is scaled according to the defined width. Example: if we define two columns with a width of 80 and 120 pixels, but want the grid to have a 300 pixels - then the columns are recalculated as follow: 1- column = 300(new width)/200(sum of all width)*80(column width) = 120 and 2 column = 300/200*120 = 180.
rowheight: (optional) Default: null. This option defines the height of the single row ( must make some experiments here). If is set the height of the grid is changed according to the number of the returned rows from the server and the scroll bar does not appear. Important note here - if you want this to work you should not change the property overflow hidden and white-space nowrap in the CSS
viewrecords: (optional) Default: false. If you want to view the total records from the query in the pager bar you should set option to true. The related tag is: records in xml or json definitions.
recordtext: (optional) This displays a text after the viewed records. The default value is in English and is: Record(s).
imgpath: (optional) Default: empty string. Whit this option you can define the path to the images that are used from the grid. Define this without a “/” at the end.
loadtext: (optional) Default: “Loading…”. With this we can change the text which apper when requesting and sorting data.
loadonce: (optional) Default: false. If this flag is set to true, the grid load only once the data from the server. All other manipulations are done at client side. Note that in this case the pager is disabled.
multiselect: (optional) Default: false. If this flag is set to true a multi selection of rows is enabled. A new column at left side is added. This can be used with server and local data.
subGrid: (optional) Default: false. Is set to true this enables using of sub grid.
subGridUrl: (optional) Default: empty string. This option has effect only if subGrid option is set to true. This describes the url for the subgrid data. Additinally to this url is added parameter “id” which is the id of the row. If using PHP we can use $id = $_GET[’id’]; to obtain the needed information of the sub grid data.
subGridModel:(optional) Default: empty array. This option has effect only if subGrid option is set to true. This option describes the model of the subgrid. The syntax is as follow: subGridModel:[{ name : [’n1′,’n2′,..,’nN’],width : [w1,w2,…,wN] }] - where n1..nN are the names which appears at the header of the sub grid and w1..wN are the widths of the columns. See example page for using a sub grid.

5. Methods

After constructing the grid we can use the following methods.

getUrl - return the current url
getSortName - return the current sortname
getSortOrder - return the current sorting order
getSelectedRow - return the current selected row
getPage - return the curent page number
getRowNum - return the current number of requested rows
setUrl(’newurl’) - set a new url
setSortName(’newsortname’) set a new sort name
setSortOrder(’newsortorder’) set a new sort order
setPage(newpage) set a new page number
setRowNum (newrownum) set a new number of requested rows.
.trigger( ‘reloadGrid’) method reloads a data with the current settings.

New Methods

getMultiRow return a one dimensional array with the selected rows id’s. Can be used if the flag multiselect is set to true.
getDataType return the current data type. Possible values are : xml, json, local.
getRecords return the number of records in grid.
setDataType(newdatatype) Set a new data type. Possible values are : xml, json, local.
getRowData(rowid) Return associative array ([name:value,..])with the values of the requested rowid. If the row can not be found the method returns empty array.
delRowData(rowid) Deletes row with the id - rowid. Return true is the operation success, otherwise false.
setRowData(rowid, data) Updates the values (using data array) in the row with the given rowid. The syntax of data array is: {name1:value1,name2: value2…} where the name is the name of the column as described in the colModel and the value is the new value. Return true on success.
addRowData(rowid,data) Insert new row with id rowid at the end of the grid using data array.The syntax of data array is: {name1:value1,name2: value2…} where the name is the name of the column as described in the colModel and the value is the value. Return true on success.
toXmlData(encoding) Return a XML string with a current data in the grid. The default encoding is utf-8.
toJSONData() Return a string in JSON format with the current data in the grid.

If you want to set new parameters a reloadGrid method load a data with a new setting.
Example:
mygrid.setPage(5);
mygrid.trigger(’reloadGrid’);

where mygrid = $(”table_id”).jqGrid(…);

loads a Page 5 from the server

A simple PHP MySQL generation of the XML File can be found here

jQuery grid plung's Documentation相关推荐

  1. php jquery grid,jQuery Grid

    jQuery Grid 能够在 ASP.NET MVC 中轻松地实现分页. 排序. 筛选以及 jQuery 插件网格中的 CRUD 操作. 具有以下特征:时尚的表格数据呈现控件. JavaScript ...

  2. jquery grid设置行背景色

    项目中有一个需求,可以根据grid中某一列的值来设置该行的背景色,效果如下图所示. 具体代码如下: var pmDetailGrid; window.onload = function(){ pmDe ...

  3. 240个jquery插件

    240个jquery插件 http://www.kollermedia.at/archive/2007/11/21/the-ultimate-jquery-plugin-list/ File uplo ...

  4. 超强1000个jquery极品插件!(连载中。。。。最近更新20090710)

    花N长时间积累的Jquery插件,希望大家喜欢.大家还有什么新的插件,请留言,我们一并收录. 感谢大家的支持. ++++++++++++++++++++++++++++++++++++++++++++ ...

  5. jQuery:收集一些基于jQuery框架开发的控件/jquery插件2

    Horizontal accordion: jQuery 基于jQuery开发,非常简单的水平方向折叠控件. 主页:http://letmehaveblog.blogspot.com/2007/10/ ...

  6. (紀錄)[ASP.NET MVC][jQuery]-1 純手工打造屬於自己的 jQuery GridView

    (我自己想記錄下來,雖然是別人寫的,但覺得很有值得保留) 在 ASP.NET MVC 中已經沒有像 ASP.NET Web Form 那樣有許多內建控制項了,而一般在開發專案上可能會滿常碰到一個需求: ...

  7. 新鲜的jquery插件收集

    参考网站http://www.noupe.com/ajax/45-fresh-out-of-the-oven-jquery-plugins.html 1.Colorful Sliders With j ...

  8. jquery plugins

    jQuery官网插件 jQuery自定义滚动条样式插件 jQuery custom content scroller examples Twitter typeahead typeahead.js t ...

  9. 转 jquery插件--241个jquery插件—jquery插件大全

    241个jquery插件-jquery插件大全 jquery插件jqueryautocompleteajaxjavascriptcoldfusion jQuery由美国人John Resig创建,至今 ...

最新文章

  1. OCS2007R2部署之一软硬件环境准备
  2. android drawpath大小,Android Path和PathMeasure
  3. Python-Django-Ajax进阶
  4. Thymeleaf 标准表达式语法
  5. [BUUCTF-pwn]——xman_2019_format
  6. java 读取1m文件_java的FileInputStream类读取文件
  7. 5G(7)---5G NR协议栈及功能2 - MAC RLC PDCP SDAP
  8. SpringBoot + Vue 开发前后端分离的旅游管理系统
  9. GPS NMEA-0183标准数据介绍
  10. spring boot 尚桂谷学习笔记07 嵌入式容器 ---Web
  11. qq红包裂变式引流?QQ群红包裂变吸粉引流
  12. pyinstaller打包有pandas和numpy库过程中遇到的bug及处理
  13. 关于数据库系统的查询处理
  14. 音视频基本概念和FFmpeg的简单入门(新手友好+FFmpeg资料分享)
  15. Android系统分区备份与还原
  16. python将房贷数据写进excel表格
  17. oracle中与归档相关的视图,Oracle OWI 等待事件历史视图及相关视图 - 一沙弥的世界...
  18. python 3.8教程_Python 3.8 新功能全解
  19. 软考嵌入式系统工程师的十大建议
  20. 快盘做网站服务器,快盘云服务器地址

热门文章

  1. 关于在win10电脑开启移动热点,手机连上wifi显示无互联网连接的问题
  2. 专业CDR插件牛为设计大师
  3. zerg发出了第一个报文,纪念一下!!!
  4. matlab 导出图片坐标_Matlab绘图---坐标系显示设置
  5. Buffer之position,limit,capacity
  6. sodo 赋予非管理员用户临时权限
  7. 高光谱图像算法实习工程师面经
  8. 【面经】TP-LINK 图像算法工程师(提前批)
  9. Kali 无线网卡无法连接到网络
  10. 支付平台--网联详解