【问题标题】:KendoGrid - Hide the detail column with conditionKendoGrid - 隐藏带有条件的详细信息列
【发布时间】:2016-03-07 11:11:37
【问题描述】:

我正在使用 KendoGrid 控件来放置分层数据。但是我想根据条件动态隐藏详细信息或子表中的一列。子网格是在主网格的 detailInit 函数的帮助下建立起来的。请建议或建议,如何即时隐藏子表col。

$(function () {
    $("#gridAudit").kendoGrid({
        dataSource: {
            data: partnergroups,
            schema: {
                model: {
                    fields: {
                        PartnerGroupID : {type: "number"},
                        PartnerName: { type: "string" },
                        OperationType: { type: "string" },
                        HasHistory: { type: "boolean" }
                    }
                }
            },
            pageSize: 10,
            sort: { field: "PartnerName", dir: "asc" }
        },
        height: 250,                    
        scrollable: true,                    
        sortable: true,
        filterable: true,                        
        detailInit: detailInitfunc,
        pageable: {
            input: true,
            numeric: true
        },
        columns: [
            { field: "PartnerName", title: "Partner Name", width: "150px" },
            { field: "OperationType", title: "Status", width: "80px" }
        ]
    }); //E.O. "kendoGrid" initialization   

});     //E.O. "DomReady"


function detailInitfunc(e) {
    $("<div/>").appendTo(e.detailCell).kendoGrid({
        dataSource: {
            data: childgroups,
            filter: { field: "PartnerGroupID", operator: "eq", value: e.data.PartnerGroupID }
        },
        scrollable: false,
        sortable: false,
        pageable: false,
        columns: [
            { field: "PartnerName", title: "Partner Name", width: "150px" },
            { field: "OperationType", title: "Status", width: "80px" },
            { field: "Revert", title: "Action", width: "80px", template: '<i class="fa fa-floppy-o fontIcon" onclick="revertData(#=HistoryID#);" title="Revert the record"></i> ' }
        ]
    });
}  //E.O. "detailInitfunc"

我想根据来自主表的 OperationType 字段的值隐藏子表中的 Revert 列。

请提出修复建议。

【问题讨论】:

    标签: javascript jquery kendo-ui kendo-grid kendo-asp.net-mvc


    【解决方案1】:

    这可以通过在创建详细信息网格时管理columns 属性轻松完成。您已经拥有的信息,它附带e.data(shortened sn-p):

    var columns = [
        { field: "PartnerName", title: "Partner Name", width: "150px" },
        { field: "OperationType", title: "Status", width: "80px" }
    ];
    
    if (e.data.OperationType == "Type #1") {
        columns.push({ field: "Revert", title: "Action", width: "80px", template: '<i class="fa fa-floppy-o fontIcon" onclick="revertData(#=HistoryID#);" title="Revert the record"></i> ' });
    }
    
    $("<div/>").appendTo(e.detailCell).kendoGrid({
        columns: columns
    });
    

    Working Demo with Full Code

    甚至更简单,设置列的hidden 属性(缩短的sn-p):

    var hidden = false;
    
    if (e.data.OperationType == "Type #1") {
        hidden = true;
    }
    
    $("<div/>").appendTo(e.detailCell).kendoGrid({
        columns: [{ field: "Revert", title: "Action", width: "80px", template: '<i class="fa fa-floppy-o fontIcon" onclick="revertData(#=HistoryID#);" title="Revert the record"></i> ', hidden: hidden }]
    });
    

    Working Demo with Full Code

    【讨论】:

    • 谢谢,我赶紧试试吧。
    • 非常感谢,工作:-)
    • @worstCoder 只要使用setOptions 在有数据或没有数据时更改它,请检查this。我建议您在dataBound 上使用它。
    • @worstCoder grid.dataSource.data().length 检查数据长度。
    • @DontVoteMeDown 谢谢人.. setOption 神奇.. 终于我的问题得到了解决
    猜你喜欢
    • 1970-01-01
    • 2014-01-26
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2014-01-18
    • 2018-05-03
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多