PDA

View Full Version : How to enable filters on page load



PT_C
2 Aug 2017, 9:55 AM
I want to filter my grid with different buttons that active certain filters. However they do not work on page load. Only when you select/deselect a filter option and then click the button, does the filter actually kick in.

The error I get when the first page loads is:


app.js:330 Uncaught TypeError: Cannot read property 'setActive' of undefined

How do I enable these filter settings when the page first loads?

Buttons

var openButton = Ext.create('Ext.Button', {
text: 'Open Topics',
handler: function () {
var filter = grid[uniqueId].filters.getFilter('TopicStateValue');
filter.setActive(true);
filter.setValue('Open/Current');
}
});
var holdButton = Ext.create('Ext.Button', {
text: 'On Hold Topics',
handler: function () {
var filter = grid[uniqueId].filters.getFilter('TopicStateValue');
filter.setActive(true);
filter.setValue('Hold');
}
});
var closedButton = Ext.create('Ext.Button', {
text: 'Closed Topics',
handler: function () {
var filter = grid[uniqueId].filters.getFilter('TopicStateValue');
filter.setActive(true);
filter.setValue('Archived/Closed');
}
});

Columns


columns: [{
text: 'Title',
width: 260,
dataIndex: 'Title',
filterable: true,
filter: {
type: 'string'
// specify disabled to disable the filter menu
//, disabled: true
}
}, {
text: 'Description',
flex: 1,
dataIndex: 'Description',
filter: {
type: 'string'
// specify disabled to disable the filter menu
//, disabled: true
}
}, {
text: 'Modified',
width: 90,
dataIndex: 'Modified',
xtype: 'datecolumn',
format: 'm/d/Y',
filter: true
}, {
text: 'Status',
width: 100,
dataIndex: 'TopicStateValue',
filter: {
active: true,
type: 'list',
value: 'Open/Current',
options: ['Open/Current', 'Archived/Closed', 'Hold']
}
}]

fiddle




(https://fiddle.sencha.com/#view/editor&fiddle/238v)

Gary Schlosberg
2 Aug 2017, 11:21 AM
I'm not seeing the error. What do I need to do to trigger it?

PT_C
2 Aug 2017, 11:35 AM
I'm not seeing the error. What do I need to do to trigger it?

The error is the buttons don't work when the page is loaded. When you click 'On Hold Topics' the grid should filter to only items with 'Hold' status. That doesn't happen in the fiddle on page load. If you open up the console when the page loads and click one of the buttons, there's an error.