【问题标题】:Pass detailrow reference in kendo grid template funciton在剑道网格模板函数中传递详细行引用
【发布时间】:2013-09-16 12:20:35
【问题描述】:

您好,有什么方法可以使用 kendo 网格模板列将 detailRow 引用传递给函数?

这是我的踪迹。

  function detailInit(e) {
            detailRow = e.detailRow;
          detailRow.find("#mygrid").kendoGrid({
                    dataSource: {
                        data: empModel,
                    },
                    columns: [
                    {
                        field: "empId",
                        title: "Emp ID",
                        template: '<a href="\\#" onclick="showEmpDetails(\'#= detailRow #\')">        }
                           ]
                 });
                });

【问题讨论】:

    标签: kendo-ui kendo-grid jquery-templates


    【解决方案1】:

    尝试将您在 detailInit 检索到的每个 detailRow 放入全局定位的数组中,然后将此索引传递给您的 click 方法(或某种键 - 可能是字典,行有 uid),然后使该方法读取根据您传入的 id 从您的数组/集合中获取行详细信息。(理想情况下,通过 uid 直接从您的数据源中读取行详细信息,无需复制数据。)请参考下面的代码作为伪代码,我没有没有机会运行它。

    var rows = new Array(); 
    
    $('.clickable').click(function () {
         // get the id for your detail
         var detailId = this.attr('detailId');
         // pass it further
         showEmpDetails(detailId);
    });
    
    function detailInit(e) {
          detailRow = e.detailRow;
          // add roe to your (cache) collection
          rows[rows.legth] =  detailRow ;
          detailRow.find("#mygrid").kendoGrid({
                dataSource: {data: empModel},
                columns: [
                    {
                        field: "empId",
                        title: "Emp ID",
                        // add attribute onto your a tag
                        template: '<a href="\\#" detailId = "#= rows.legth #" class="clickable">' 
                    }
                          ]
                 });
    });
    
    function showEmpDetails(id) {
         // read from your collection and do what you need
         console.log(rows[id]);
    }
    

    【讨论】:

    • 我认为这很好。但是我们可以在不存储在全局数组中的情况下做到这一点吗?有什么解决办法吗?
    • 是的,不是使用全局数组,而是通过 uid 直接引用 datasource.data()。此解决方案的问题是您必须遍历 data() 才能找到您的行,这可能需要相当长的时间,而且 uid 是一个 guid,而不是 html 标签公开的最佳选择。我至少会查找如上所示的索引和 uid,例如,您仍将实际数据存储在数据源中,但通过 uid 和数组索引/键的字典获取它们。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2023-03-09
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多