下表列出了jqGrid中的預定義格式化類型
所有預定義類型和編輯模式兼容,就是說數字,鏈接和email等需要轉換,才能使他們被正確編輯
類型 | 選項(默認值參考語言選項) | 描述 |
---|---|---|
integer | thousandsSeparator, defaulValue |
|
number | decimalSeparator, thousandsSeparator, decimalPlaces, defaulValue |
|
currency | decimalSeparator, thousandsSeparator, decimalPlaces, defaulValue, prefix, suffix |
和number一樣,知識多了2個選項
|
date | srcformat, newformat, parseRe |
|
none | 設置email將會給內容添加鏈接,鏈接地址為mailto:emai內容 | |
link | target | target 默認值為null。設置為這個,會構造一個連接,添加target屬性,單元格內容作為href屬性值 |
showlink | baseLinkUrl, showAction, addParam, target, idName |
|
checkbox | disabled | disabled默認值為true。控制checkbox是否能被改變。設置為false,可以膝蓋checkbox的值。 |
select | none | 不是真實的select,僅為一個特例,看下面的說明 |
actions | { keys: false, editbutton : true, delbutton : true, editformbutton: false, onEdit : null, onSuccess: null, afterSave:null, onError: null, afterRestore: null, extraparam: {oper:'edit'}, url: null, delOptions: {}, editOptions : {} } |
在行編輯模式這個類型的格式化函數很容易給指定的列添加一個按鈕。 有2中類型的動作,編輯和刪除。 editformbutton設置為true 將醫用表單編輯對話框,取代行編輯模式 editOptions僅用於配置表單編輯模式。 |
"Select"格式化函數
select類型不是真實的select。這個用於使用某些編輯模式下,設置了edittype:'select'的情況。這個版本之前grid顯示select的值,而不是鍵(Before this release we pass the value of the select in grid and not the key),例如:
-收縮
JavaScript
代碼
jQuery(
"#grid_id").jqGrid({
...
colModel : [ {name:'myname', edittype:'select', editoptions:{value:"1:One;2:Two"}} ... ],
...
});
...
colModel : [ {name:'myname', edittype:'select', editoptions:{value:"1:One;2:Two"}} ... ],
...
});
這個情況下,grid的數據需要包含"One"或者"Two",設在myname這個列里面。配置formatter為select的代碼如下
-收縮
JavaScript
代碼
jQuery(
"#grid_id").jqGrid({
...
colModel : [ {name:'myname', edittype:'select', formatter:'select', editoptions:{value:"1:One;2:Two"}} ... ]
...
});
...
colModel : [ {name:'myname', edittype:'select', formatter:'select', editoptions:{value:"1:One;2:Two"}} ... ]
...
});
數據包含鍵名稱(“1” or “2”),但是值 (“One”, or “Two”) 將會顯示在grid里面。
showlink 示例
看下面的代碼
-收縮
JavaScript
代碼
jQuery(
"#grid_id").jqGrid({
...
colModel: [ {name:'myname', formatter:'showlink', formatoptions:{baseLinkUrl:'someurl.php', addParam: '&action=edit'}, ...}
...
]
...
});
...
colModel: [ {name:'myname', formatter:'showlink', formatoptions:{baseLinkUrl:'someurl.php', addParam: '&action=edit'}, ...}
...
]
...
});
上面將會得到下面的輸出
http://localhost/someurl.php?id=123&action=edit
如果你想將生成的url中id鍵名稱修改為myid,可以這樣設置
-收縮
JavaScript
代碼
jQuery(
"#grid_id").jqGrid({
...
colModel: [ {name:'myname', formatter:'showlink', formatoptions:{baseLinkUrl:'someurl.php', addParam: '&action=edit', idName:'myid'}, ...}
...
]
...
});
...
colModel: [ {name:'myname', formatter:'showlink', formatoptions:{baseLinkUrl:'someurl.php', addParam: '&action=edit', idName:'myid'}, ...}
...
]
...
});
上面將會得到下面的輸出
http://localhost/someurl.php?myid=123&action=edit