2012-07-05 20 views
0

我一直在尋找在SlickGrideditors/formatters功能,以瞭解這些將修改用於構建電網的data對象(因爲據我瞭解,修改表中取得會自動複製到data對象)。與SlickGrid複選框格式/編輯數據不一致

我看其示出了如何booleans可以編輯和格式化爲複選框(代替處理一個truefalse字符串),發現複製到data對象中的值是不一致的特定示例。

要明白我的意思,編輯effortDriven列第4行,如下所示:
- 任務0:不要碰
- 任務1:檢查
- 任務2 :不要碰
- 任務3:檢查並取消

enter image description here

現在,在您的螢火控制檯,提醒數據對象:

enter image description here

這裏是你將得到的effortDriven字段中的值:
- 任務0true
- 任務1checked
- 任務2false
- 任務3(void 0)

正如你所看到的,對於用於最初應該是一個boolean一個領域,我們結束了4倍不同的值。作爲一般性評論,我認爲formatters/editors的邏輯只是爲了檢查可視化,但保留了data對象的完整性:因此,我強烈建議使用SlickGrid的人仔細檢查data對象在使用formatters/editors時如何更新,並且不要假設數據完整性被保留)。

如何確保我的data對象保留了2 boolean的值,同時仍然使用UI上的複選框?

回答

0

編輯CheckboxEditor功能slick.editors.js如下:

this.applyValue = function (item, state) { 
    //item[args.column.field] = state; <-- remove that line, add lines below 
    if (state == 'checked') { 
     item[args.column.field] = true; 
    } else { 
     item[args.column.field] = false; 
    } 
}; 
0

我發現這個問題爲好。在定製CheckboxEditorslick.editors.js只需更改數值串化器:

function CheckboxEditor(args) { 

    ... 

    this.serializeValue = function() { 
     return $select.attr("checked") ? true : false; 
    }; 

    ... 

}