當編輯列爲edittype: select
和multiple: true
時,jqGrid將數據作爲逗號分隔值發送到服務器。有可能綁定一些事件到這個特定的列,這將返回一個數組而不是逗號分隔的值?jqGrid,編輯模式,序列化多選
我想避免使用serializeEditData事件,因爲
- 這一個是電網專用,不列具體這將是我的一個麻煩 - 我試圖分開列邏輯從網格邏輯
- 它聽起來不是一個好主意,將數組轉換爲字符串,並再次將字符串轉換爲相同的數組。
當編輯列爲edittype: select
和multiple: true
時,jqGrid將數據作爲逗號分隔值發送到服務器。有可能綁定一些事件到這個特定的列,這將返回一個數組而不是逗號分隔的值?jqGrid,編輯模式,序列化多選
我想避免使用serializeEditData事件,因爲
我認爲,你將不得不在的情況下使用edittype: 'custom'
和提供的editoptions
custom_element
和custom_value
方法您的自定義實現。如果自定義輸入元素的值將需要讀取,則jqGrid將使用參數'get'
參數調用custom_value
方法。你的實現custom_value
方法可能會返回大小寫的項目。
重要的是要明白,一般來說,您將需要實現自定義格式化程序,該程序允許顯示多列表輸入的數據數組。幸運的formatter: "select"
有the line
cellval = cellval + "";
其將數組逗號分隔的項目。由於該行數組將通過使用.join(",")
轉換爲字符串,並且formatter: "select"
成功接受數組作爲輸入。
演示上面的方法所描述的。它使用下面的代碼:
{
name: "Subcategory",
width: 250,
formatter: "select",
edittype: "custom",
editoptions: {
value: {"1": "football", "2": "formula 1", "3": "physics", "4": "mathematics"},
custom_element: function (value, options) {
return $.jgrid.createEl.call(this, "select",
$.extend(true, {}, options, {custom_element: null, custom_value: null}),
value);
},
custom_value: function ($elem, operation, value) {
if (operation === "get") {
return $elem.val();
}
},
multiple: true
}
}
在上面的代碼中,我使用$.jgrid.createEl
創建多值由現有的jqGrid代碼的選擇。唯一需要做的就是從選項中刪除custom_element
和custom_value
,以防止setAttributes中不需要的方法調用。如果將修改setAttributes
的the line代碼並且在排除的屬性的列表中包括"custom_value"
和"custom_element"
,則可以將表達$.extend(true, {}, options, {custom_element: null, custom_value: null})
減少爲options
。
以這種方式,我們得到幾乎相同的<select>
與使用edittype: "select"
。只有兩點不同:內部
<select>
元素的edittype: "custom"
內部創建將有額外的屬性class="customelement"
edittype: "custom"
中創建的<select>
元素將被包裝(會直接子)<span class="editable">...</span>
這種差異在我們的案例中似乎並不重要。
修訂:setAttributes
方法的代碼現在固定的jqGrid對gtihub主代碼(參見the suggestion和the commit)。因此,在jqGrid的(如較高4.4.1)的下一個版本一個可能的custom_element
代碼減少
custom_element: function (value, options) {
return $.jgrid.createEl.call(this, "select", options, value);
}
我期待你的答案在這裏奧列格!謝謝! – migajek
@migajek:不客氣!在遠程保存數據的情況下,我不測試m建議,但我認爲它的工作方式完全相同。 – Oleg
@ migajek:我寫了小小的「** UPDATED **」部分給我的回答。 – Oleg