Kendoui Grid在数据源中发送动态变量

时间:2014-03-12 09:59:18

标签: javascript jquery kendo-ui kendo-grid kendo-datasource

我正在尝试"过滤"基于从选择下拉列表中选择的选项的网格。

当选择下拉列表中的更改事件触发时,如何将所选选项值发送到网格?

我的网格数据源是:

dataSourceParts = new kendo.data.DataSource({
    serverPaging: false,
    serverFiltering: false,
    serverSorting: false,
    transport: {
        read: {
            url: ROOT + 'shipment/partsSerialGrid',
            dataType: 'json',
            type: 'POST',
            data: {
                enquiryId: enquiryId
            }
        }
    },
    pageSize: 25,
    error: function(e) {
        alert(e.errorThrown + "\n" + e.status + "\n" + e.xhr.responseText);
    },
    schema: {
        data: "data",
        total: "rowcount",
        model: {
            id: 'id',
            fields: {
                quantity: {
                    type: 'number',
                    editable: false
                },
                idealForm: {
                    type: 'string',
                    editable: false
                },
                serial: {
                    type: 'string',
                    editable: true
                }
            }
        }
    }
})

我的选择事件:

$('#fromNameSelect').change(function() {
            var fromMode = $('#fromSelect').val();
            if (fromMode == 2)
            {
                supplierId = $(this).val();
                dataSourceParts.filter({
                    field: 'test', operator: 'eq', value: 'test' // THIS DOES NOTHING.
                });
                $('#shippingPartsGrid').data('kendoGrid').dataSource.read();
            }
        })

2 个答案:

答案 0 :(得分:0)

我无法证实这一点。但是因为你在dataSourceParts中设置过滤器。你不应该使用dataSourceParts.read()代替$('#shippingPartsGrid').data('kendoGrid').dataSource.read();吗?

答案 1 :(得分:0)

$('#fromNameSelect').change(function() {
            var fromMode = $('#fromSelect').val();
            if (fromMode == 2)
            {
                supplierId = $(this).val();
                 $('#shippingPartsGrid').data('kendoGrid').dataSource.filter({
                    field: 'test', operator: 'eq', value: 'test' // DO IT LIKE THIS
                });
            }
        })