[英]Kendo Grid Cancel event restores hidden buttons
我有一個帶有行按鈕的劍道網格,我根據訪問頁面的用戶隱藏了這些按鈕:對於某些用戶,只有“編輯”按鈕可見,而對於其他用戶,“刪除”和“添加”按鈕將可見。 我使用一個功能來做到這一點,在檢查用戶及其權限后,隱藏按鈕如下:
$("#grid").find(".k-grid-delete").hide();
$("#grid").find(".k-grid-edit").show();
$("#grid").find(".k-grid-add").hide();
這工作正常,但是如果只有“編輯”按鈕可見的用戶單擊“編輯”,然后單擊“取消”按鈕,則網格將自身恢復為“正常”並且所有按鈕都可見。 我試過攔截“取消”事件,並調用隱藏按鈕的函數,但網格的重繪顯然是在取消事件完成后發生的。 我已經嘗試過數據綁定,但是取消操作時不會引發數據綁定。 我需要攔截在單擊“取消”之后和重繪網格之前發生的事件。
有任何想法嗎?
最后,使用功能構建工具欄和命令選項比在構建網格后有條件地刪除某些按鈕更簡單。 即在劍道網格定義函數中:
var grid = $("#grid").kendoGrid({
dataSource: dataSource,
toolbar: setToolbarCreateButton(),
columns: [
{ field: "COL1" },
{ field: "COL2" },
{ field: "COL3" },
{
command: setCommandRow(),
title: " ",
width: "250px"
}
],
(rest of configuration here)
});
在函數 setCommandRow() 和 setToolbarCreateButton() 中,根據條件返回按鈕的定義:
// Returns an array of objects with the buttons for the command bar IF those buttons are visible
function setToolbarCreateButton() {
if (checkEditable(false)) return [{ name: "create" }];
else return null;
}
和
// Returns an array of objects with the buttons for the row IF those buttons are visible
function setCommandRow() {
var cmdRow = [];
if (checkEditable(true)) cmdRow.push({ name: "edit" });
if (checkEditable(false)) cmdRow.push({name: "destroy" });
return cmdRow;
}
checkEditable() 當然是確定編輯或銷毀按鈕是否可用的方法。 通過這種方式,我不是使按鈕可見或不可見,而是根據條件創建或不創建按鈕。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.