Thursday, January 15, 2015

ExtJs 5.1 GridPanel Plugin gridfilters Example Getting Start


Here we will use plugins: 'gridfilters', for adding filter functionality in GridPanel.
This plugins: 'gridfilters', is new plugin has been added in ExtJS 5.1 for filter to reduce a lot of codes.

Use this plugins: 'gridfilters', in create/define during Ext.grid.Panel and then add filter: 'string', in each column to get this filter functionality.



<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8"/>
    <title>Extjs 5.1 Grid Panel</title>
    <link rel="stylesheet" href="extjs-5.1.0/packages/ext-theme-gray/build/resources/ext-theme-gray-all.css"/>
    <script src="extjs-5.1.0/extjs5.1.0-all-dashboard.js"></script>
    <script>
Ext.onReady(function(){
 console.log("I am ready now");

 Ext.define('Student',{
 extend: 'Ext.data.Model',
 fields: ['id','name','mobile']
 });

    var studentStore = Ext.create('Ext.data.Store',{
model: 'Student',
autoLoad: true,
data:[
{status: true, id:'1', name:'Binod', mobile:'0000059257'},
{status: false, id:'5', name:'Ishan', mobile:'0002887325'},
{status: true, id:'3', name:'Akshu', mobile:'00351070277'},
{status: false, id:'4', name:'Sanjay', mobile:'999988885'},
{status: true, id:'2', name:'Zambia', mobile:'8888999997'}
]

});


Ext.create('Ext.grid.Panel',{
renderTo: Ext.getBody(),
store: studentStore,
width: 450,
height: 200,
title: 'Student Records',
plugins: 'gridfilters',
columns:[
{xtype: 'checkcolumn', text: 'Status', filter: 'string', dataIndex:'status', width: 50},
{text: 'Roll Number', filter: 'string', dataIndex:'id', width: 100},
{text: 'Name' , filter: 'string',dataIndex:'name', width: 100},
{text: 'Mobile' , filter: 'string',dataIndex:'mobile', flex: 1}
],



dockedItems: [{
        xtype: 'pagingtoolbar',
        store: studentStore,   // same store GridPanel is using
        dock: 'bottom',
        displayInfo: true
    }]

});


});

</script>
</head>
</html>

Now if you click on any column, you will get filter functionality.

No comments:

Post a Comment

You can put your comments here (Either feedback or your Question related to blog)