【问题标题】:Handling null value in kendo grid处理剑道网格中的空值
【发布时间】:2016-06-07 19:45:16
【问题描述】:

我有一个剑道网格,其中一列可以有空值。但是当有空值时,我看不到网格填充。我的代码在这里:

$(document).ready(function() {
    $("#grid").kendoGrid({
        dataSource: gridData,
        columns: [{
            field: "name",
            title: "Name"
        }, {
            field: "result",
            title: "Result",
            template: "# if (result == null) { #" +
                "<span data-content=' '></span> } #" +
                "# } else { #" +
                "<span data-content=\"#: result#\"> </span>"
        }]
    });
});

谁能帮我解决这个问题。

【问题讨论】:

    标签: javascript html kendo-ui kendo-grid


    【解决方案1】:

    我不确定您是否真的需要自己设置data-content...如果您只想设置一个空字符串而不是空值,您可以使用更简单的模板来完成:

    $(document).ready(function() {
        $("#grid").kendoGrid({
            dataSource: gridData,
            columns: [{
                field: "name",
                title: "Name"
            }, {
                field: "result",
                title: "Result",
                template: "#= (result == null) ? ' ' : result #"
            }]
        });
    });
    

    【讨论】:

    • 我也试过了。但它说“结果未定义”并且网格仍然没有显示。
    • 啊!好的,我以为您指的是该列的数据。你能告诉我们你是如何得到gridData的吗?你能检查一下当你到达kendoGrid初始化时它是否被定义?
    • 我正在使用 post call 来获取数据。数据源是这样的:
    • 没有模板也可以正常工作。但不是当我使用模板时。
    【解决方案2】:

    为了更容易控制/阅读,您可以这样做

    $(document).ready(function() {
        $("#grid").kendoGrid({
            dataSource: gridData,
            columns: [{
                field: "name",
                title: "Name"
            }, {
                title: "Result",
                template: function (dataItem) {
                    if (dataItem.result == null)
                        return 'Placeholder';
                    else
                        return dataItem.result;
                }
            }]
        });
    });
    

    个人不喜欢剑道插值'#',当模板中的逻辑较多时很难阅读,这可能导致更多的插值'#'。使代码不可读导致起点和终点都使用'#'。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2015-06-24
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2014-12-15
      • 2013-11-07
      相关资源
      最近更新 更多