var <?php echo $gridStore;?> = new Ext.data.Store({
    url: '<?php echo $ajax;?>',
    baseParams:{
        action: '<?php echo $storeAction;?>'
    },
    
    remoteSort: true,
    reader: new Ext.data.JsonReader({
            root: 'rows',
            totalProperty: 'results'
        },
        new Ext.data.Record.create([
            { name: 'id', type: 'id' },
            { name: 'holder', type: 'string' },
            { name: 'firstname', type: 'string' },
            { name: 'surname', type: 'string' },
            { name: 'address', type: 'string' },
            { name: 'city', type:'string' },
            { name: 'post_code', type: 'string' },
            { name: 'gender', type: 'string' },
            { name: 'birth_date', type:'string' },
            { name: 'datum_dostave', type: 'string' },
            { name: 'order_date', type: 'string' },
            { name: 'addedDate', type: 'string' }
        ])
    ),
    listeners:{
        beforeLoad:function()  {
            Ext.getCmp('<?php echo $gridName;?>').getEl().mask('<?php echo $LangPack->GetLabel("CRM_all", "loading_mask_text","Posodabljanje...");?>');
        },
        load: function(resp,r,o){
        	//console.log(resp.reader.jsonData.sql);
        	Ext.getCmp('numberRecordsLabel').setText(resp.data.length);
        	Ext.getCmp('<?php echo $gridName;?>').getEl().unmask();
        }
    }
});

var <?php echo $gridName;?> = new Ext.grid.EditorGridPanel({
    id: '<?php echo $gridName;?>',
    store: <?php echo $gridStore;?>,
    region: 'center',
    
    border: false,
    sm: new Ext.grid.RowSelectionModel(),
    tbar:[{
       xtype: 'button',
       text:'<?php echo $LangPack->GetLabel("clubMembersTab", "advanced_search_button_label", "Advanced Search");?>',
       handler: function(){
           CallScript('CRM/_forms/_modules/windowSearch/window.search-filter.php', { grid: '<?php echo $gridName;?>'});
       } 
    },'->',{
        xtype:'button',
        disabled: true,
        id:'clubMembersExportButton',
        text: '<?php echo $LangPack->GetLabel("CRM_all", "CRM_export_button", "Export");?>',
        handler: function(){                
            var store = Ext.getCmp('<?php echo $gridName;?>').getStore();
            if(typeof(store.reader.jsonData) !== 'undefined')    
                if(store.data.items.length != 0)
                    window.open("<?php echo $ajax;?>?action=export&token="+store.reader.jsonData.exportTokenValue).focus();
                else{
                    Ext.Msg.alert('<?php echo $LangPack->GetLabel("clubMembersTab", "msg_box_title", "No results");?>', '<?php echo $LangPack->GetLabel("clubMembersTab", "msg_box_text_no_rows", "Sorry there were no results found");?>');   
                }
            else{
                Ext.Msg.alert('<?php echo $LangPack->GetLabel("clubMembersTab", "msg_box_title", "No results");?>', '<?php echo $LangPack->GetLabel("clubMembersTab", "msg_box_text", "Please use the serch first");?>');
            }
        }
    }],
    bbar:['->','<?php echo $LangPack->GetLabel("clubMembersTab", "result-n-label", "Number of records:");?> ',
    {
    	xtype: 'label',
    	id : 'numberRecordsLabel',
    	text : '/',
    	style : 'margin-right:20px'
    }
    ],
    columns:[{
        header: '#ID',
        dataIndex: 'id',
        hidden: true
    },{
        header: '<?php echo $LangPack->GetLabel("clubMembersTab", "holder_column_label", "Holder");?>',
        dataIndex: 'holder',
        sortable: true
    },{
        header: '<?php echo $LangPack->GetLabel("clubMembersTab", "firstname_column_label", "Firstname");?>',
        dataIndex: 'firstname',
        sortable: true
    },{
        header: '<?php echo $LangPack->GetLabel("clubMembersTab", "surname_column_label", "Surname");?>',
        dataIndex: 'surname',
        sortable: true
    },{
        header: '<?php echo $LangPack->GetLabel("clubMembersTab", "address_column_label", "Address");?>',
        dataIndex: 'address',
        sortable: true
    },{
        header: '<?php echo $LangPack->GetLabel("clubMembersTab", "city_column_label", "City");?>',
        dataIndex: 'city',
        sortable: true
    },{
        header: '<?php echo $LangPack->GetLabel("clubMembersTab", "post_code_column_label", "Post code");?>',
        dataIndex: 'post_code',
        sortable: true
    },{
        header: '<?php echo $LangPack->GetLabel("clubMembersTab", "gender_column_label", "Gender");?>',
        dataIndex: 'gender',
        sortable: true  
    },{
        header: '<?php echo $LangPack->GetLabel("clubMembersTab", "birth_date_column_label", "Birth date");?>',
        dataIndex: 'birth_date',
        sortable: true  
    },{
        header: '<?php echo $LangPack->GetLabel("clubMembersTab", "delivery_date_column_label", "Delivery date");?>',
        dataIndex: 'datum_dostave',
        sortable: true
    },{
        header: '<?php echo $LangPack->GetLabel("clubMembersTab", "order_date_column_label", "Order date");?>',
        hidden: true,
        dataIndex: 'order_date',
        sortable: true
    },{
        header:'<?php echo $LangPack->GetLabel("clubMembersTab", "acctivity_added_date_column_label", "Activity added date");?>',
        dataIndex: 'addedDate',
        sortable: true
    }]
});