jsgrid插件>过滤器无法使用" POST"要求JSON

时间:2018-03-22 10:56:43

标签: javascript jsgrid

我有这段代码:

$("#jsGrid").jsGrid({
    height: "auto",
    width: "100%",
    sorting: true,
filtering: true,
    paging: false,
    autoload: true,
    pageLoading: false,

    controller: {
        loadData: function(filter) {    

    var d = $.Deferred();
             $.ajax({
                processData: false,
                type:"POST",
                url: "http://blabla/api/database/sp",
                data: JSON.stringify(storedproceduredata),
                headers: {
                    'Content-Type': 'application/json',
                    'Accept': 'application/json',
                dataType: 'json'
            }).done(function(response) {
                if (filter) {
                    if (filter.field1 && filter.field1 != "")
                        response.results = response.results.filter(r => r.field1 === filter.field1);
                    if (filter.ID_field2 && filter.ID_field2 != "")
                        response.results = response.results.filter(r => r.field2 === filter.ID_field2);
                    if (filter.field2 && filter.field3 != "")
                        response.results = response.results.filter(r => r.field3 === filter.field3);
                }                   d.resolve(response.results);
            });

            return d.promise();
        }
    },

    fields: [
        { name: "field1", type: "text" },
        { name: "field2", type: "text", width: 150 },
    { name: "field3", type: "text", width: 150 }
    ]
});
});

我试图让过滤器使用$ .grep示例,但它无法正常工作。这可能有什么问题?

过滤器对象填充了我的过滤器字段。但在某些示例中,数据参数也是" filter"。在我的情况下这是不可能的因为我需要它来获取我的数据。

Response对象是这样的:

Response
  results
     1
        Field1     value
        Field2     another value 
     2
        Field1      value
        Field2      another value

 etc..... 

0 个答案:

没有答案