【问题标题】:jsGrid data not showing after adding select box添加选择框后未显示jsGrid数据
【发布时间】:2018-09-26 09:54:50
【问题描述】:

我的目标是在我的网格系统中添加选择框,我成功地按照以下代码添加选择框。

但在添加选择框后,我的其他数据没有显示,当我从下拉过滤器中搜索时,它正在显示数据。

$("#jsGrid").jsGrid({
    height: 480,
    width: "100%",

    filtering: true,
    editing: false,
    sorting: true,
    paging: true,
    autoload: true,
    clearFilterButton: true,

    pageSize: 10,
    pageButtonCount: 10,


    controller: {
        loadData: function(filter) {
            criteria = filter;
            var data = $.Deferred();
            $.ajax({
                type: "GET",
                contentType: "application/json; charset=utf-8",
                url: "myURL",
                dataType: "json"
            }).done(function(response) {
                var res = [];
                if (criteria.component !== "") {
                    response.forEach(function(element) {
                        if (element.component.indexOf(criteria.component) > -1) {
                            res.push(element);
                            response = res;
                        }
                    }, this);
                } else res = response;
                if (criteria.titleLong !== "") {
                    res = [];
                    response.forEach(function(element) {
                        if (element.titleLong.indexOf(criteria.titleLong) > -1)
                            res.push(element);
                    }, this);
                } else res = response;

                data.resolve(res);
            });
            return data.promise();
        }

    },

    fields: [{
        name: "component",
        type: "textarea",
        width: 150
    }, {
        name: "Id",
        type: "text",
        width: 50
    }, {
        name: "titleLong",
        type: "select",
        align: "center", // center text alignment
        autosearch: true, // triggers searching when the user changes the selected item in the filter
        items: ["", "A", "B", "C"], // an array of items for select
        valueField: "", // name of property of item to be used as value
        textField: "", // name of property of item to be used as displaying value
        selectedIndex: -1, // index of selected item by default
        valueType: "string", // the data type of the value
        readOnly: false, // a boolean defines whether select is readonly (added in v1.4)
    }, {
        name: "unit",
        type: "textarea",
        width: 150
    }, {
        name: "descr",
        type: "textarea",
        width: 150
    }]
});

所以我的目标是显示页面加载时的所有数据,如果有人使用选择过滤器执行搜索,则显示执行搜索的相关数据。

【问题讨论】:

    标签: php jquery jsgrid


    【解决方案1】:

    可能,在第三个字段定义中从“readOnly: false”中删除“,”会有所帮助。

    【讨论】:

    • 尾随逗号在 JavaScript 对象声明中无效
    • @ChrisM:这个尾随逗号在 Internet Explorer (11.0.9600.19301) 中有效,它给出错误:SCRIPT1028: Expected identifier, string or number
    • 您可能对函数参数定义的尾随逗号感到困惑,这在 IE 中失败但在其他主要浏览器中有效。 IE 从 IE9 开始支持对象声明中的尾随逗号(根据 MDN:developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/…
    • 我创建了一个测试用例,演示 IE11 如何在对象声明中支持尾随逗号,但不支持函数参数:jsbin.com/pazuniyapi
    • 如果您在 IE11 中仍然看到此错误 - 可能是您在兼容模式下运行文档。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2014-04-21
    • 1970-01-01
    相关资源
    最近更新 更多