我試圖使用jqGrid格式化程序:遠程json url的「actions」,但它會移動行,因爲列名和實際返回的數據數不匹配行列在列名中是多餘的)。我在線搜索,它看起來像所有的例子是本地數據(在頁面上),其中json用作鍵/值,而url:somepage.php返回一列csv種類的格式(沒有鍵,只是值) 。我也使用id作爲隱藏字段,而所有示例都顯示id。我還使用了一個隱藏列。 這裏是我的colmodel:jqGrid:格式化程序:「actions」不適用於遠程json url
url: "manager_json",
editurl: "manager_edit",
datatype: "json",
//data: mydata,
width:1000,
//jsonReader: {
// repeatitems : false,
// },
colNames: ["","Id","Uid","Custom Id","Image Name","Coord. X","Coord. Y","Gender","Progress","Status","Created","Updated"],
colModel: [{"name":"act","template":"actions","formatoptions":{"editformbutton":true}},{"name":"id","align":"center","width":33,"editable":false,"hidden":true},{"name":"uid","align":"center","width":33,"editable":true,"hidden":true,"editrules":{"edithidden":false,"required":false}},{"name":"ta_id","align":"center","width":100,"editrules":{"required":true}},{"name":"image","width":150,"template":"text","editrules":{"required":true}},{"name":"x","width":100,"align":"center","template":"integer","editrules":{"required":true}},{"name":"y","width":100,"align":"center","template":"integer","editrules":{"required":true}},{"name":"gender","width":100,"align":"center","formatter":"select","stype":"select","editrules":{"required":true},"edittype":"select","editoptions":{"value":"f:Female;m:Male","defaultValue":"m"},"searchoptions":{"sopt":["eq","ne"],"value":":Any;f:Female;m:Male"}},{"name":"progress","width":120,"align":"center","formatter":"select","stype":"select","editrules":{"required":true},"editable":false,"edittype":"select","editoptions":{"value":"-:New;pf:Process Failed;ps:Process Scheduled;pss:Process Success;p:Processing...;s:Staging;tf:Test Failed;ts:Test Scheduled;tss:Test Success;t:Testing...","defaultValue":"m"},"searchoptions":{"sopt":["eq","ne"],"value":":Any;-:New;pf:Process Failed;ps:Process Scheduled;pss:Process Success;p:Processing...;s:Staging;tf:Test Failed;ts:Test Scheduled;tss:Test Success;t:Testing..."}},{"name":"status","width":100,"align":"center","formatter":"select","stype":"select","edittype":"select","editoptions":{"value":"a:Active;n:New","defaultValue":"m"},"searchoptions":{"sopt":["eq","ne"],"value":":Any;a:Active;n:New"}},{"name":"date_created","width":150,"template":"text","editable":false},{"name":"last_updated","width":150,"template":"text","editable":false}]
這裏是我從我的服務器(DB)按jqGrid的規範實際數據:
{"page":1,"total":1,"records":7,"rows":[{"id":32,"cell":[32,"889daf31ff3e49544f52850258439600","2uu","2ok",2,2,"m","-","a","2017-02-10 18:57:05","2017-02-10 23:37:12"]},{"id":30,"cell":[30,"","11","11",1,1,"m","-","a","2017-02-10 18:01:52","2017-02-10 18:01:52"]},{"id":29,"cell":[29,"aaa","ww222111uu","11",1,1,"m","-","a","2017-02-10 18:00:36","2017-02-10 23:37:08"]},{"id":27,"cell":[27,"","11","1",1,1,"m","-","a","2017-02-10 17:57:41","2017-02-10 17:57:41"]},{"id":25,"cell":[25,"","4tt","4img",4,4,"f","-","n","2017-02-10 17:50:21","2017-02-11 00:26:03"]},{"id":24,"cell":[24,"","1","1",1,1,"m","-","a","2017-02-10 17:49:38","2017-02-10 17:49:38"]},{"id":22,"cell":[22,"","bbb","imam 222",2,22,"f","p","n","2017-02-08 20:14:55","2017-02-10 13:27:57"]}]}
正如你可以看到單元行具有比colNames
和colModel
少列。還id和uid
列被隱藏。我說從DB額外的假柱,但它並沒有幫助
我使用的jqGrid 4.13.7預
原因我打算使用數組格式(不是字典格式),因爲我期望每頁大約有5000行,因此可以最大限度地減少加載時間和大小。建議的數據格式有所幫助。現在工作。謝謝奧列格。 – LSP
@LSP:不客氣!你應該[「接受」](http://meta.stackexchange.com/a/5235/147495)答案,如果它解決了你的問題。我建議你使用頁面大小對應於可以在監視器上顯示的行數,例如'rowNum:25'或'rowNum:20'。 'rowNum:5000'的使用使頁面變得更慢,對用戶沒有任何好處。嘗試[演示](http://www.ok-soft-gmbh.com/jqGrid/OK/performane-15-60000-25-free-jqgrid.htm),每頁有60000行和10行。它的速度更快,1000行,每頁1000行。 – Oleg
我沒有看到任何說「接受這個答案」的按鈕......它在哪裏? – LSP