javascript - jsGrid 不会渲染 JSON 数据

标签 javascript jquery json asp.net-mvc jsgrid

我尝试在我的 MVC 项目中使用 jsGrid,因为客户端想要内联编辑和过滤。 但是,我无法让它将 JSON 源加载到表中。 我加载表格的 js 看起来像这样:

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

            filtering: true,
            inserting: true,
            editing: true,
            sorting: true,
            paging: true,
            autoload: true,

            pageSize: 10,
            pageButtonCount: 5,

            deleteConfirm: "Do you really want to delete client?",

            controller: {
                loadData: function (filter) {
                    return $.ajax({
                        type: "GET",
                        url: "RICInstrumentCode/GetData",
                        data: filter,
                        dataType: "json"
                    });
                },

                insertItem: function (item) {
                    return $.ajax({
                        type: "CREATE",
                        url: "/api/RICInsrumentCodeTable",
                        data: item,
                        dataType: "json"
                    });
                },

                updateItem: function (item) {
                    return $.ajax({
                        type: "UPDATE",
                        url: "/api/RICInsrumentCodeTable/" + item.ID,
                        data: item,
                        dataType: "json"
                    });
                },

                deleteItem: $.noop

                //deleteItem: function (item) {
                //    return $.ajax({
                //        type: "DELETE",
                //        url: "/api/data/" + item.ID,
                //        dataType: "json"
                //    });
                //}
            },

            fields: [
                { name: "Code", type: "text", title: "RIC Instrument Code", width: 150 },
                { name: "Descr", type: "text", title:"RIC Instrument Code Description", width: 200 },
                { name: "RICInstrumentGroupId", type: "select", title: "RIC Instrument Group", items: countries, valueField: "Id", textField: "Name" },
                { name: "Active", type: "checkbox", title: "Is Active", sorting: true },
                { type: "control" }
            ]
        });

    });

loadData 是我一直在研究的内容。

从获取数据返回的 JSON 如下所示:

[{"Id":1,"Code":"test1","Descr":"first code test","RICInstrumentGroupId":2,"Active":true},{"Id":2,"Code":"APP","Descr":"Apples and bananas","RICInstrumentGroupId":4,"Active":true},{"Id":3,"Code":"1","Descr":"1","RICInstrumentGroupId":1,"Active":true},{"Id":4,"Code":"3","Descr":"3","RICInstrumentGroupId":3,"Active":false}]

到目前为止,我已经确认 ajax 正在触发,更改了我的数组标题以匹配调用的标题,并确保返回是有效的 JSON,我还能做什么?为什么这不起作用?

最佳答案

我本来就很傻, 设置表格高度的位在没有高度的 div 中设置为 100%,这导致表格主体以 0px 的高度渲染,更改高度属性以自动修复它,因为数据一直都在那里.

谢谢你的建议!

关于javascript - jsGrid 不会渲染 JSON 数据,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/41039447/

相关文章:

javascript - 移动到 monorepo 后重新设置分支

javascript - Twitter Bootstrap 警报消息关闭并再次打开

javascript - jquery - 旋转一次

javascript - 再次: AJAX -> storing result in variable using callback (undefined)

javascript - 数组中的每个字符都被 javascript 中的 ".hasOwnProperty(i)"识别为 Google Apps 脚本的 true

javascript - 根据水平滚动检查元素是否在视口(viewport)中

javascript - 如何检测图片路径是否有效?

jquery - 为搜索词结果添加背景颜色

python - 将文件解析为 JSON 文件的父/子格式

android - 在 "org.json.JSONException: Value{data}"中获取 JSONArray 结果