我在 ASP.NET Core 中有一个 Devexpress 网格。它工作正常,但我需要添加一个自定义按钮以重定向到具有所选 id 的另一个操作。
我试过这个:
columns.AddFor(m => m.Remark).Visible(false).Caption("ملاحظات").Alignment(HorizontalAlignment.Right);
columns.AddFor(m => m.AddDate).Caption("تاريخ الاضافة").Alignment(HorizontalAlignment.Right);
columns.AddFor(m => m.SanadNumber).Caption("رقم السند").Alignment(HorizontalAlignment.Right);
columns.AddFor(m => m.FullName).Caption("بواسطة").Alignment(HorizontalAlignment.Right);
columns.Add()
.Type(GridCommandColumnType.Buttons)
.Buttons(b =>
{
b.Add()
.Icon("add")
.OnClick(@<text>ButtonClick()</text>);
});
现在我需要这个函数
ButtonClick
来将参数ID
传递给函数。
<script>
function attachButtonClick(ID)
{
window.location.replace(/MYview/ID)
};
</script>
我在这里找到了一个示例,它向我们展示了点击处理函数,恐怕你提到的
selected id
可以从e.row.data
中获取,如果它在行内,或者我们可以使用js选择器来获取它基于 e.row.rowIndex
的 id,rowIndex
有助于定位。
columns.Add()
.Type(GridCommandColumnType.Buttons)
.Width(110)
.Buttons(b => {
b.Add().Name(GridColumnButtonName.Edit);
b.Add().Name(GridColumnButtonName.Delete);
b.Add()
.Hint("Clone")
.Icon("copy")
.Visible(new JS("isCloneIconVisible"))
.Disabled(new JS("isCloneIconDisabled"))
.OnClick("onCloneIconClick");
});
function onCloneIconClick(e) {
var clonedItem = $.extend({}, e.row.data, { ID: ++maxID });
employees.splice(e.row.rowIndex, 0, clonedItem);
e.component.refresh(true);
e.event.preventDefault();
}