Skip to content
This repository was archived by the owner on Apr 25, 2022. It is now read-only.
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions packages/mf-grid-filter-form/examples/index.html
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
<html>
<header>
<link rel="stylesheet" href="https://extjs.cachefly.net/ext/gpl/5.1.1/build/packages/ext-theme-crisp/build/resources/ext-theme-crisp-all.css" type="text/css">
<script type="text/javascript" src="https://extjs.cachefly.net/ext/gpl/5.1.1/build/ext-all.js"></script>
<script type="text/javascript" src="../build/mf-grid-filter-form-debug.js"></script>
<link rel="stylesheet" href="../../../ext/build/packages/ext-theme-crisp/build/resources/ext-theme-crisp-all.css" type="text/css">
<script type="text/javascript" src="../../../ext/build/ext-all.js"></script>
<script type="text/javascript" src="./build/mf-grid-filter-form-debug.js"></script>
<script>
Ext.onReady(function () {
var store, columns,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,13 @@ Ext.define('SimpleGrid.view.grid.RemoteNumberGrid', {
text: 'Description',
dataIndex: 'description',
flex: 1,
filterOption: {
operator: '<='
}
}, {
text: 'Date',
dataIndex: 'date',
flex: 1,
filterOption: {}
}],

Expand Down
3 changes: 2 additions & 1 deletion packages/mf-grid-filter-form/src/grid/feature/FilterForm.js
Original file line number Diff line number Diff line change
Expand Up @@ -281,7 +281,8 @@ Ext.define('Mayflower.grid.feature.FilterForm', {
config = Ext.apply(config, item.filterOption, {
fieldLabel: item.text,
name: item.dataIndex,
stateId: me.title + '-' + item.dataIndex
stateId: me.title + '-' + item.dataIndex,
operator: 'like'
});

return config;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,8 @@ Ext.define('Mayflower.grid.feature.FilterFormController', {
onApplyFilters: function () {
var view = this.getView(),
store = view.up().getStore(),
formValues = view.getForm().getValues(),
filters = this.buildFilter(formValues);
form = view.getForm(),
filters = this.buildFilter(form);

store.clearFilter(true);

Expand Down Expand Up @@ -49,20 +49,21 @@ Ext.define('Mayflower.grid.feature.FilterFormController', {
/**
* Build filters for given form values, as consumed by {@see Ext.store.Store#setFilters Store setFilters} function.
*
* @param {Object} formValues
* @param {Ext.form.Basic} form
* @returns {Function[]} array of filter functions
*
* @private
*/
buildFilter: function (formValues) {
var filters = [];
buildFilter: function (form) {
var filters = [],
formFields = form.getFields().items;

Ext.iterate(formValues, function (key, value) {
if (!Ext.isEmpty(value)) {
Ext.iterate(formFields, function (key, value) {
if (!Ext.isEmpty(key.value)) {
filters.push(new Ext.util.Filter({
operator: 'like',
property: key,
value: value
operator: key.operator,
property: key.name,
value: key.value
}));
}
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,25 @@ describe('Mayflower grid filter form controller test suite', function () {
var controller = Ext.create('Mayflower.grid.feature.FilterFormController');

it('should return the correct filter', function () {
var filters = controller.buildFilter({a: 'a', b: 'b'}),
item = {
a: 'a'
};
/*
var filters = controller.buildFilter(
Ext.create('Ext.form.Panel', {
items: [{
fieldLabel: 'First Name',
name: 'first',
allowBlank: false
},{
fieldLabel: 'Last Name',
name: 'last',
allowBlank: false
}]
}
)
);
expect(filters.length).toBe(2);
expect(filters[0].filter(item)).toBeTruthy();
expect(filters[1].filter(item)).toBeFalsy();
*/
});
});
});
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,9 @@ describe('Mayflower grid filter form test suite', function () {
columns = [{
text: 'Id',
dataIndex: 'id',
filterOption: {}
filterOption: {
operator: '<='
}
}, {
text: 'Name',
dataIndex: 'name',
Expand Down Expand Up @@ -67,9 +69,12 @@ describe('Mayflower grid filter form test suite', function () {

expect(filterForm.items.getAt(0).xtype).toEqual('textfield');
expect(filterForm.items.getAt(0).getFieldLabel()).toEqual('Id');
expect(filterForm.items.getAt(0).operator).toEqual('<=');


expect(filterForm.items.getAt(1).xtype).toEqual('textfield');
expect(filterForm.items.getAt(1).getFieldLabel()).toEqual('Name');
expect(filterForm.items.getAt(1).operator).toEqual('like');

expect(filterForm.getDockedItems().length).toEqual(1);
expect(filterForm.getDockedItems()[0].xtype).toEqual('toolbar');
Expand Down