0
votes

I'm migrating from extjs 2.2 to extjs 4.0. My code filters my grid data trough an php (the proxy url) that POST the some ext fields.

etx store:

var store = Ext.create('Ext.data.Store', {
    model: 'Company',
    remoteSort: true,
    remoteFilter: true,
    proxy: {
        // load using script tags for cross domain, if the data in on the same domain as
        // this page, an HttpProxy would be better
        type: 'ajax',
        url: "logica_de_aplicacao/usuario/grid_usuarios_dados.php",
        reader: {
            root: 'results',
            totalProperty: 'total'
        },
        // sends single sort as multi parameter
        simpleSortMode: true
    },
    sorters: [{
        property: 'nome',
        direction: 'ASC'
    }]
});

ext fields (two exemples, there are too many fields):

var txtLogin = new Ext.form.TextField({
                    fieldLabel: "Login",
                    width: 200
                });

var txtAtivo = new Ext.form.ComboBox({
                    fieldLabel: 'Ativo',
                    width: 200,
                    name: 'ativo',
                    editable: false,
                    disableKeyFilter: true,
                    forceSelection: true,
                    triggerAction: 'all',
                    mode: 'local',
                    store: new Ext.data.SimpleStore({
                        id: 0,
                        fields: ['value', 'text'],
                        data : [['S', 'Sim'], ['N', 'Não']]
                    }),
                    valueField: 'value',
                    displayField: 'text',
                    hiddenName: 'ativo'
                });

Filtering:

tbar: [{
        text: "Adicionar Filtro", //add filter
        tooltip: "Filtre os resultados",
        iconCls:"icone_filtro",
        handler: function() {
            iniciaPesquisa();
        }
    }, {
        text: "Remover Filtro", //remove filter
        tooltip: "Cancelar o filtro",
        iconCls:"icone_cancel_filtro",
        handler: function() {
            store.baseParams = {
                login: "",
                nome: "",
                privilegio: "",
                ativo: "",
                municipio: ""
            };
            store.removeAll();
            store.load();

        }
    }],

PHP:

...
$login = $_POST["login"];
...
$ativo = $_POST["ativo"];

In ext 2.2 that would normally post the fields content on the store.load() action, but nothing happens now. How could I post those fields in ext 4?

(apologizes for the bad english)

2

2 Answers

0
votes

It's actually simpler now, just use store.clearFilter()

store.clearFilter();
store.removeAll();
store.load();
0
votes
var store = Ext.create('Ext.data.Store', {
    model: 'Company',
    remoteSort: true,
    remoteFilter: true,
    proxy: {
        // load using script tags for cross domain, if the data in on the same domain as
        // this page, an HttpProxy would be better
        type: 'ajax',
        url: "logica_de_aplicacao/usuario/grid_usuarios_dados.php",
baseParams: {  //here you can define params you want to be sent on each request from this store
                        login: "",
                nome: "",
                privilegio: "",
                ativo: "",
                municipio: ""
                        },
        reader: {
            root: 'results',
            totalProperty: 'total'
        },
        // sends single sort as multi parameter
        simpleSortMode: true
    },
    sorters: [{
        property: 'nome',
        direction: 'ASC'
    }]
});

tbar: [{
        text: "Adicionar Filtro", //add filter
        tooltip: "Filtre os resultados",
        iconCls:"icone_filtro",
        handler: function() {
            iniciaPesquisa();
        }
    }, {
        text: "Remover Filtro", //remove filter
        tooltip: "Cancelar o filtro",
        iconCls:"icone_cancel_filtro",
        id : 'BtnRemoveFilter', // added this
        handler: function() {
            store.baseParams = {
                login: "",
                nome: "",
                privilegio: "",
                ativo: "",
                municipio: ""
            };
            store.removeAll();
            store.load();

        }
    }],

var Btn = Ext.getCmp('BtnRemoveFilter');
    Btn.on('click', function(){
        store.load({
                        params: {  //here you can define params on 'per request' basis
                                login: "the value u want to pass",
                nome: "the value u want to pass",
                privilegio: "the value u want to pass",
                ativo: "the value u want to pass",
                municipio: "the value u want to pass"
                                }
                        })
    });

try this code is working or not.i think this is what u want