jqGrid 資料之 Json

來源:互聯網
上載者:User

標籤:strong   資料   re   c   ar   伺服器   

Json資料

需要定義jsonReader來跟伺服器端返回的資料做對應,其預設值:

· jsonReader : {  

·      root: "rows",  

·      page: "page",  

·      total: "total",  

·      records: "records",  

·      repeatitems: true,  

·      cell: "cell",  

·      id: "id",  

·      userdata: "userdata",  

·      subgrid: {root:"rows",   

·         repeatitems: true,   

·        cell:"cell"  

·      }  

 

這樣伺服器端返回的資料格式:

· {   

·   total: "xxx",   

·   page: "yyy",   

·   records: "zzz",  

·   rows : [  

·     {id:"1", cell:["cell11", "cell12", "cell13"]},  

·     {id:"2", cell:["cell21", "cell22", "cell23"]},  

·       ...  

·   ]  

· }

jsonReader的屬性

total

總頁數

page

當前頁

records

查詢出的記錄數

rows

包含實際資料的數組

id

行id

cell

當前行的所有儲存格

 

自訂:

· jQuery("#gridid").jqGrid({  

· ...  

·    jsonReader : {  

·       root:"invdata",  

·       page: "currpage",  

·       total: "totalpages",  

·       records: "totalrecords",  

·       cell: "invrow"  

·    },  

· ...  

· }); 

· totalpages: "xxx",   

·   currpage: "yyy",  

·   totalrecords: "zzz",  

·   invdata : [  

·     {id:"1", invrow:["cell11", "cell12", "cell13"]},  

·     {id:"2", invrow:["cell21", "cell22", "cell23"]},  

·       ...  

·   ]  

repeatitems 
  指明每行的資料是可以重複的,如果設為false,則會從返回的資料中按名字來搜尋元素,這個名字就是colModel中的名字

· jsonReader : {  

·       root:"invdata",  

·       page: "currpage",  

·       total: "totalpages",  

·       records: "totalrecords",  

·       repeatitems: false,  

·       id: "0"  

·    }

·  totalpages: "xxx",   

·   currpage: "yyy",  

·   totalrecords: "zzz",  

·   invdata : [  

·     {invid:"1",invdate:"cell11", amount:"cell12", tax:"cell13", total:"1234", note:"somenote"},  

·     {invid:"2",invdate:"cell21", amount:"cell22", tax:"cell23", total:"2345", note:"some note"},  

·       ...  

·   ]  

此例中,id屬性值為“invid”。 
一旦當此屬性設為false時,我們就不必把所有在colModel定義的name值都賦值。因為是按name來進行搜尋元素的,所以他的排序也不是按colModel中指定的排序結果。

使用者資料(user data) 
在某些情況下,我們需要從伺服器端返回一些參數但並不想直接把他們顯示到表格中,而是想在別的地方顯示,那麼我們就需要用到userdata標籤

· jsonReader: {  

·   ...  

·   userdata: "userdata",  

·   ...  

· } 

· {   

·   total: "xxx",   

·   page: "yyy",   

·   records: "zzz",   

·   userdata: {totalinvoice:240.00, tax:40.00},   

·   rows : [   

·     {id:"1", cell:["cell11", "cell12", "cell13"]},   

·     {id:"2", cell:["cell21", "cell22", "cell23"]},   

·     ...   

·   ]   

· }

在用戶端我們可以有下面兩種方法得到這些額外資訊:

1.      jQuery("grid_id").getGridParam(‘userData‘)  

2.      jQuery("grid_id").getUserData()  

3.      jQuery("grid_id").getUserDataItem( key )  

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在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.