JqGrid 完整例子

來源:互聯網
上載者:User

JqGrid 例子  可以參考   http://blog.mn886.net/jqGrid/

完整執行個體壓縮包  http://download.csdn.net/detail/ruthywei/9888200

jqGrid學習之 ------------- 安裝

jqGrid安裝很簡單,只需把相應的css、js檔案加入到頁面中即可。 
按照官網文檔:

/myproject/css/ 
            ui.jqgrid.css 
            /ui-lightness/ 
                  /images/ 
                  jQuery-ui-1.7.2.custom.css

 /myproject/js/ 
            /i18n/ 
                  grid.locale-bg.js 
                  list of all language files 
                  ….
            jquery-1.3.2.min.js 
            jquery.jqGrid.min.js

 

在頁面中寫法:

Java代碼 

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">  

<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">  

<head>  

<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />  

<title>My First Grid</title>  

   

<link rel="stylesheet" type="text/css" media="screen" href="css/ui-lightness/jquery-ui-1.7.1.custom.css" />  

<link rel="stylesheet" type="text/css" media="screen" href="js/src/css/ui.jqgrid.css" />  

<link rel="stylesheet" type="text/css" media="screen" href="js/src/css/jquery.searchFilter.css" />  

<style>  

html, body {  

   margin: 0;  

    padding: 0;  

    font-size: 75%;  

}  

</style>  

   

<script src="js/jquery-1.3.2.min.js" type="text/JavaScript"></script>  

<script src="js/src/grid.loader.js" type="text/javascript"></script>  

   

</head>  

<body>  

...  

</body>  

</html>  

需要說明的是,jquery-ui的字型大小與jqgrid字型大小不一致,故需要在頁面上在加上一段 
style來指定頁面上文字大小。

  jqGrid皮膚

從3.5版本開始,jqGrid完全支援jquery UI的theme。我們可以從http://jqueryui.com/themeroller/下載我們所需要的theme。當然,你也可以編輯自己的theme。jqGrid 
也並不需要把所有的css檔案都引入進來,只需匯入核心css檔案“ui.theme.css ” 以及“ui.core.css”即可,檔案位於目錄development-bundle/themes下。 jqGrid原理

jqGrid是典型的B/S架構,伺服器端只是提供資料管理,用戶端只提供資料顯示。換句話說,jqGrid可以以一種更加簡單的方式來展現你資料庫的資訊,而且也可以把用戶端資料傳回給伺服器端。 
對於jqGrid我們所關心的就是:必須有一段代碼把一些頁面資訊儲存到資料庫中,而且也能夠把響應資訊返回給用戶端。jqGrid是用ajax來實現對請求與響應的處理。 jqGrid參數

名稱

類型

描述

預設值

可修改

url

string

擷取資料的地址

 

 

datatype

string

從伺服器端返回的資料類型,預設xml。可選類型:xml,local,json,jsonnp,script,xmlstring,jsonstring,clientside

 

 

mtype

string

ajax提交方式。POST或者GET,預設GET

 

 

colNames

Array

列顯示名稱,是一個數組對象

 

 

colModel

Array

常用到的屬性:name 列顯示的名稱;index 傳到伺服器端用來排序用的列名稱;width 列寬度;align 對齊;sortable 是否可以排序

 

 

pager

string

定義翻頁用的導覽列,必須是有效html元素。翻頁工具列可以放置在html頁面任意位置

 

 

rowNum

int

在grid上顯示記錄條數,這個參數是要被傳遞到後台

 

 

rowList

array

一個下拉選擇框,用來改變顯示記錄數,當選擇時會覆蓋rowNum參數傳遞到後台

 

 

sortname

string

預設的排序列。可以是列名稱或者是一個數字,這個參數會被提交到後台

 

 

viewrecords

boolean

定義是否要顯示總記錄數

 

 

caption

string

表格名稱

 

 

ajaxGridOptions[a1] 

object

對ajax參數進行全域設定,可以覆蓋ajax事件

null

ajaxSelectOptions[a2] 

object

對ajax的select參數進行全域設定

null

altclass

String

用來指定行顯示的css,可以編輯自己的css檔案,只有當altRows設為 ture時起作用

ui-priority-secondary

 

altRows

boolean

設定表格 zebra-striped 值

 

 

autoencode

boolean

對url進行編碼

false

autowidth

boolean

如果為ture時,則當表格在首次被建立時會根據父元素比例重新調整表格寬度。如果父元素寬度改變,為了使表格寬度能夠自動調整則需要實現函數:setGridWidth

false

cellLayout

integer

定義了儲存格padding + border 寬度。通常不必修改此值。初始值為

5

cellEdit

boolean

啟用或者禁用儲存格編輯功能

false

cellsubmit

String

定義了儲存格內容儲存位置

‘remote’

cellurl

String

儲存格提交的url

空值

datastr

String

xmlstring或者jsonstring

空值

deselectAfterSort

boolean

只有當datatype為local時起作用。當排序時不選擇當前行

true

direction

string

表格中文字的顯示方向,從左向右(ltr)或者從右向左(rtr)

ltr

editurl

string

定義對form編輯時的url

空值

emptyrecords

string

當返回的資料行數為0時顯示的資訊。只有當屬性 viewrecords 設定為ture時起作用

 

ExpandColClick

boolean

當為true時,點擊展開行的文本時,treeGrid就能展開或者收縮,不僅僅是點擊圖片

true

ExpandColumn

string

指定那列來展開tree grid,預設為第一列,只有在treeGrid為true時起作用

空值

footerrow[a3] 

boolean

當為true時,會在翻頁欄之上增加一行

false

forceFit

boolean

當為ture時,調整列寬度不會改變表格的寬度。當shrinkToFit 為false時,此屬性會被忽略

false

gridstate

string

定義當前表格的狀態:'visible' or 'hidden'

visible

gridview

boolean

構造一行資料後添加到grid中,如果設為true則是將整個表格的資料都構造完成後再添加到grid中,但treeGrid, subGrid, or afterInsertRow 不能用

false

height

mixed

表格高度,可以是數字,像素值或者百分比

150

hiddengrid

boolean

當為ture時,表格不會被顯示,只顯示表格的標題。只有當點擊顯示表格的那個按鈕時才會去初始化表格式資料。

false

hidegrid

boolean

啟用或者禁用控製表格顯示、隱藏的按鈕,只有當caption 屬性不為空白時起效

true

hoverrows

boolean

當為false時mouse hovering會被禁用

false

jsonReader

array

描述json 資料格式的數組

 

lastpage

integer

唯讀屬性,定義了總頁數

0

lastsort

integer

唯讀屬性,定義了最後排序列的索引,從0開始

0

loadonce

boolean

如果為ture則資料只從伺服器端抓取一次,之後所有操作都是在用戶端執行,翻頁功能會被禁用

false

loadtext

string

當請求或者排序時所顯示的文字內容

Loading....

loadui

string

當執行ajax請求時要幹什麼。disable禁用ajax執行提示;enable預設,當執行ajax請求時的提示; block啟用Loading提示,但是阻止其他動作

enable

multikey

string

只有在multiselect設定為ture時起作用,定義使用那個key來做多選。shiftKeyaltKeyctrlKey

空值

multiboxonly

boolean

只有當multiselect = true.起作用,當multiboxonly 為ture時只有選擇checkbox才會起作用

false

multiselect

boolean

定義是否可以多選

false

multiselectWidth

integer

當multiselect為true時設定multiselect列寬度

20

page

integer

設定初始的頁碼

1

pagerpos

string

指定分頁欄的位置

center

pgbuttons

boolean

是否顯示翻頁按鈕

true

pginput

boolean

是否顯示跳轉頁面的輸入框

true

pgtext

string

當前頁資訊

 

prmNames

array

Default valuesprmNames: {page:“page”,rows:“rows”, sort: “sidx”,order: “sord”, search:“_search”, nd:“nd”, npage:null} 當參數為null時不會被發到伺服器端

none

postData

array

此數組內容直接賦值到url上,參數類型:{name1:value1…}

空array

reccount

integer

唯讀屬性,定義了grid中確切的行數。通常情況下與records屬性相同,但有一種情況例外,假如rowNum=15,但是從伺服器端返回的記錄數是20,那麼records值是20,但reccount值仍然為15,而且表格中也只顯示15

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

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.