【问题标题】:How to call custom link by clicking button from datatable ColumnProperty in nopcommerce 4.3如何通过单击 nopcommerce 4.3 中数据表 ColumnProperty 中的按钮来调用自定义链接
【发布时间】:2021-03-16 07:17:20
【问题描述】:

我想从 datatable ColumnProperty 调用链接,方法是点击 nopcommerce 4.3 中的按钮或任何 url。

这是我的数据表代码,

@await Html.PartialAsync("Table", new DataTablesModel
{
    Name = "customerjama-grid",
    Length = Model.CustomerJamaSearchModel.PageSize,
    LengthMenu = Model.CustomerJamaSearchModel.AvailablePageSizes,                      
    ColumnCollection = new List<ColumnProperty>
    {
        new ColumnProperty(nameof(CustomerJamaModel.Date))
            {
                Title = T("Admin.Customer.Jama.Fields.Date").Text,
                Width = "200"
            },
        new ColumnProperty(nameof(CustomerJamaModel.Id))
        {
            Title = T("Admin.Common.PDF").Text,
            Width = "100",                        
            ClassName = NopColumnClassDefaults.Button,
            Render = new RenderCustom("CallController"),
        }
    }
})

现在,为此我使用 datatableRenderCustom 属性,但问题是 RenderCustom 中的 "CallController" strong> 页面加载时调用javascript CallController函数。

但我的要求是,当点击与他们的controller/javascript url相关的链接时,应该触发

【问题讨论】:

  • 能否分享一下CallController的js代码?

标签: javascript url datatable controller nopcommerce


【解决方案1】:

如果我理解正确,您可以在脚本中使用:

      function CallController(data, type, row, meta) 
{
    return '<button onclick="javascript:window.location.href='+ yourlink + '
    ?id=' + data + '; return false;" class="btn btn-default">
    <i class="fa fa-print"></i>@T("Admin.Common.PDF")</button>';
};

或者,如果您想使用自己的控制器和操作,请使用:

 function CallController(data, type, row, meta) 
{
    return '<button onclick="javascript:window.location.href=
    ' + @Url.Action("yourAction", "yourController") + '?id=' + data + ';
    return false;" class="btn btn-default">
    <i class="fa fa-print"></i>@T("Admin.Common.PDF")</button>';
};

请检查 ' 和 "

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2017-04-26
    • 1970-01-01
    • 2015-12-11
    • 1970-01-01
    • 2023-01-16
    • 2016-10-14
    • 2016-03-30
    • 1970-01-01
    相关资源
    最近更新 更多