ExtJS在具有不同参数的按钮单击事件上重新加载存储

时间:2011-06-16 11:32:00

标签: servlets extjs4

我是ExtJs的新手,我正在使用ExtJs4。

现在如下图所示,有一个名为keywords的文本域,我想要做的是当我点击按钮时,它会将textfield的数据传递给servlet并在{{1}中显示结果记录}。

enter image description here

现在我不知道该怎么做。我从servlet接收JSON数据响应,但不知道如何重新加载存储并刷新网格。

  

以下是我的商店和网格的代码。

grid

3 个答案:

答案 0 :(得分:3)

您可以使用:

{
    xtype: 'button',
    text: 'Search',
    handler: function() {
        store.clearFilter(); //clear previous search value
        var searchValue = Ext.getCmp("textFieldId").getValue(); //get new value 
        store.load().filter('jsonGridFielName', searchValue); //load filtered data
    }
}

适用于多个textfield搜索:

//FILTERS
var searchValue1 = Ext.getCmp("textFieldId1").getValue(); //value1
var searchValue2 = Ext.getCmp("textFieldId2").getValue(); //value2
var noValue = "0000xxxx"; //no Value, for empty field, use value that you are sure it is not going to be searched!!!
var clear = store.clearFilter(); //shortcut

if (!searchValue1 && !searchValue2) {
    clear;
    store.load().filter("jsonGridFielName1", noValue);
} else if (searchValue1) {
    clear;
    store.load().filter('jsonGridFielName1', searchValue1);
    //...else if(searchValue n...)...
} else {
    clear;
    store.load().filter('jsonGridFielName2', searchValue2);
}

答案 1 :(得分:2)

ezdigrid.js


// Data store for grid start
Ext.define("Post", {
    extend: 'Ext.data.Model',
    proxy: {
        type: 'ajax',
        url: '/ezdi/searchServlet',
        method: 'GET',
        reader: {
            type: 'json',
            root: 'rows'
            //,totalProperty: 'totalCount'
        }
    },

    fields: [{
        name: 'docid',
        mapping: 'docid'
    }, {
        name: 'mrn',
        mapping: 'mrn'
    }, {
        name: 'fname',
        mapping: 'fname'
    }]
});

var gridDataStore = Ext.create('Ext.data.Store', {
    // pageSize: 10,
    model: 'Post'
});

// Data store for grid end

Ext.define('Ezdi.Grid', {
    extend: 'Ext.grid.GridPanel',
    alias: 'widget.ezdigrid',
    initComponent: function() {
        var config = {
            store: gridDataStore,
            columns: [{
                //id:'ms',
                header: "DocID",
                width: 100,
                sortable: true,
                dataIndex: 'docid'
            }, {
                header: "MRN",
                width: 100,
                sortable: true,
                dataIndex: 'mrn'
            }, {
                header: "FirstName",
                width: 100,
                sortable: true,
                dataIndex: 'fname'
            }],
            viewConfig: {
                forceFit: false,
                autoLoad: false
            },
            loadMask: true
        }; // eo config object

        // apply config
        Ext.apply(this, Ext.apply(this.initialConfig, config));


        // call parent
        Ezdi.Grid.superclass.initComponent.apply(this, arguments);

        // load the store at the latest possible moment
        this.on({
            afterlayout: {
                scope: this,
                single: true,
                fn: function() {
                    this.store.load({
                        params: {
                            start: 0,
                            limit: 30
                        }
                    });
                }
            }
        });

    } // eo function initComponent

});

demo.html


//handler for button click event
fbar: [{
    xtype: 'button',
    text: 'Search',
    handler: function() {
        var value = Ext.getCmp('_keyword').getValue(); //_keyword is textField
        gridDataStore.load().filter('keywords', value);
    }
}]

MyServlet


keyword = request.getParameter("keywords");

//code for quesry processing

答案 2 :(得分:2)

extraParams

中使用model
extraParams: {
    keywords: 'your-value'
}

将以下代码放入按钮点击处理程序中。

gridDataStore.proxy.extraParams.keywords = 'new value';
gridDataStore.load();