Extjs 4网格排序后自定义函数调用 [英] Custom function call after Extjs 4 grid sort

查看:90
本文介绍了Extjs 4网格排序后自定义函数调用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个具有排序功能的 Extjs 4 网格。每次用户按下排序按钮后,我想调用一个保存功能。

I have an Extjs 4 grid with sort capability. i want to call a custum function after each time user presses sort button.

在我的自定义功能中,我想导航到我的网格的第一页(我的网格使用分页,它利用服务器端排序)我想我必须使用 store.loadPage(1)在我的自定义功能(纠正我,如果我错了)

In my custom function i want to navigate to the first page of my grid (my grid uses pagination and it takes advantage of server-side sort) i think i must use store.loadPage(1) in my custom function (correct me if I'm wrong)

我应该在哪里放我的自定义功能?

where should i put my custom function?

这是我的 Ext.OnReady()功能:

Ext.onReady(function() {
Ext.tip.QuickTipManager.init();

var url = {
    local:  'grid-filter.json',  // static data file
    remote: 'grid-filter.php'
};
var paging = true;
var encode = false;
var local = false;
Ext.define('UserDirectoryDataModel', {
    extend : 'Ext.data.Model',
    fields : [ 'uname', 'fname', 'lname', 'postcode', 'mail', {
        name : 'pass'
    }, 'hasAccess', 'isActive', 'lastVisit' , 'deleteUser'],
    idProperty : 'uname'
});

var itemsPerPage = 20;   

var store = Ext.create('Ext.data.Store', {
    pageSize : itemsPerPage,
    autoLoad: false,
    local: false,
    autoDestroy: true,
    model : 'UserDirectoryDataModel',
    autoSync : true,
    sortOnLoad : true,
    remoteSort:true,
    sorters : {
        property : 'uname',
        direction : 'ASC'
    },
    listeners: {
        beforeload: function(){
            store.loadPage(1);
        }
    },

    proxy : {
        type : 'ajax',
        url: (local ? url.local : url.remote),
        api : {
            read : 'read.php',
            update : 'update.php'

        },
        reader : {
            type : 'json',
            root : 'users',
            successProperty : 'success',
            totalProperty : 'totalCount'
        },
        writer : {
            type : 'json',
            writeAllFields : true,
            encode : false,
            root : 'users'
        },
        afterRequest : function(request, success) {
            if (request.action == 'update') {
                if (success) {
                    Ext.MessageBox.alert('alert',
                            'data updated!');

                }
            }

        }
    }
});

store.load({
    params:{
        start:0,
        limit: itemsPerPage
    }
});


 var filters = {
    ftype: 'filters',
    encode: encode, // json encode the filter query
    local: local,   // defaults to false (remote filtering)
    filters: [
        {
        }
    ]
};
var createColumns = function (finish, start) {

    var columns = [ {
        text : "username",
        dataIndex : 'uname',
        width : 150,
        filterable: true,
        align : 'right'
    }, {
        text : "name",
        dataIndex : 'fname',
        width : 150,
        align : 'right',
        hidden : false,
        sortable : true,
        filterable: true,
        editor : {
            xtype : 'textfield',
            allowBlank : false
        }
    }, {
        text : "last name",
        dataIndex : 'lname',
        width : 150,
        align : 'right',
        sortable : true,
        filterable: true,
        editor : {
            xtype : 'textfield',
            allowBlank : false
        }
    }, {
        text : "PostalCode",
        dataIndex : 'postcode',
        width : 110,
        align : 'right',
        sortable : true,
        filterable: true,
        editor : {
            xtype : 'textfield',
            allowBlank : false
        }
    }, {
        text : "email",
        dataIndex : 'mail',
        width : 200,
        align : 'right',
        sortable : true,
        filterable: true,
        editor : {
            xtype : 'textfield',
            allowBlank : false
        }
    }, {
        text : "password",
        width : 150,
        align : 'right',
        sortable : false,
        filterable: true,
        hidden : true,
        dataIndex : 'pass',
        editor : {
            xtype : 'textfield',
            inputType : 'password',
            allowBlank : true
        }
    }, {
        text : "access to system",
        dataIndex : 'hasAccess',
        renderer:function(value){
            if(value[0]=="1"){
                return "<a href=\"?action=access&type=revoke&cn="+value.substring(1,value.length)+"\">has</a>";
            }else{
                return "<a href=\"?action=access&type=grant&cn="+value.substring(1,value.length)+"\">doens't have</a>";
            }
        },
        width : 100,
        align : 'center',
        sortable : false,
        filterable: false
    }, {
        text : "active",
        dataIndex : 'isActive',
        renderer:function(value){
            if(value==null)
                return;
            if(value[0]=="1"){
                return "<a href=\"?action=activation&type=grant&cn="+value.substring(1,value.length)+"\">no</a>";
            }else if(value[0]=="0"){
                return "<a href=\"?action=activation&type=revoke&cn="+value.substring(1,value.length)+"\">yes</a>";
            }else if(value[0]=="2"){
                return "Not in portal!";
            }
        },
        width : 100,
        align : 'center',
        sortable : false,
        filterable: false
    }, {
        text : "last visit",
        dataIndex : 'lastVisit',
        width : 120,
        hidden : true,
        align : 'right',
        sortable : true,
        filterable: true
    }, {
        text : " ",
        dataIndex : 'uname',
        renderer:function(value){
            return "<a href=\"?action=delete&type=deleteUser&cn="+value+"\">delete</a>";
        },
        width : 120,
        hidden : true,
        align : 'right'
    } ];

    return columns.slice(start || 0, finish);
};

var pluginExpanded = true;
var grid = Ext.create('Ext.grid.Panel', {
    border: false,
    width : 1200,
    height : 620,
    title : '',
    store: store,
    disableSelection : false,
    seltype : 'rowmodel',
    loadMask : true,
    viewConfig : {
        id : 'gv',
        trackOver : false,
        stripeRows : false,
        plugins : [ {
            ptype : 'preview',
            bodyField : 'excerpt',
            expanded : true,
            pluginId : 'preview'
        } ]
    },
    columns: createColumns(),

    features: [filters],
     dockedItems: [Ext.create('Ext.toolbar.Paging', {
        dock: 'bottom',
        store: store
    })],
    plugins : [ Ext.create('Ext.grid.plugin.RowEditing', {
        clicksToEdit : 2
    }) ],
    renderTo : 'userdatagrid'
});
grid.child('pagingtoolbar').add([
           {
        text: 'show filters',
        handler: function () {
            var data = Ext.encode(grid.filters.getFilterData());
            Ext.Msg.alert('show filters',data);
        } 
    },{
        text: 'delete filters',
        handler: function () {
            grid.filters.clearFilters();
        } 
    }
]);

store.loadPage(1);
});


推荐答案

或者你可以使用这个:

grid.on('sortchange', function() {
    grid.getStore().loadPage(1);
});

这篇关于Extjs 4网格排序后自定义函数调用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆