2014-04-03 38 views
0

我想爲以下項目製作kendo模板:編輯,刪除。kendoui模板DELETE和EDIT

{ 
    field: "Action", 
    template: '<a href="../edit/custom" ><span> EDIT</span></a> <a href="" class="deleteCustom"><span> DELETE</span>' 
} 

當我點擊刪除我需要一個確認彈出,之後重定向到URL刪除並刷新劍道但

$('.deleteCustom').onclick.. 

不起作用。我試過在字段模板+命令

{ field: "Activate", width: "100px", 
          template:"<span>edit<span>" 
          command: ["destroy"], title: " ", width: "160px", 

          }, 

但模板消失。爲什麼?命令是否重疊?我應該放置左邊什麼?

回答

1

首先,你的第一個模板有一個語義問題。你不關閉最後一個<a>標籤:

{ 
    field: "Action", 
    template: '<a href="../edit/custom"><span>EDIT</span></a> <a href="" class="deleteCustom"><span>DELETE</span></a>' 
} 

那麼你應該使用jQuery的on()的點擊綁定到你的刪除/編輯鏈接:

$('.deleteCustom').on('click', function() { 
    // Here goes your confirmation... 
}); 

爲了讓行,你應該使用這個信息:

$('.deleteCustom').on('click', function() { 
    var dataItem = grid.dataItem($(this).closest("tr")); 

    if (window.confirm("Are your sure to delete " + dataItem.title + "?")) { 
     location.href = "delete/" + dataItem.id; 
    } 
}); 

考慮到grid是劍道網格實例。

+1

得到kendo網格它會是'var grid = $(「#Grid」)。data(「kendoGrid」);' – CSharper

+0

@CSharper是的。 – DontVoteMeDown

+0

非常感謝yoyu。我會嘗試你的建議。 – studentsss