How to use the tubular-common.CompareOperators.Between function in tubular-common

To help you get started, we’ve selected a few tubular-common examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github unosquare / tubular-nodejs / src / connectors / jsondata.js View on Github external
subset = subset.filter(row => !row[filterableColumn.name].toLowerCase().endsWith(filterableColumn.filter.text));
                break;
            // TODO: check for types
            case CompareOperators.Gt:
                subset = subset.filter(row => row[filterableColumn.name] > filterableColumn.filter.text);
                break;
            case CompareOperators.Gte:
                subset = subset.filter(row => row[filterableColumn.name] >= filterableColumn.filter.text);
                break;
            case CompareOperators.Lt:
                subset = subset.filter(row => row[filterableColumn.name] < filterableColumn.filter.text);
                break;
            case CompareOperators.Lte:
                subset = subset.filter(row => row[filterableColumn.name] <= filterableColumn.filter.text);
                break;
            case CompareOperators.Between:
                subset = subset.filter(row => row[filterableColumn.name] > filterableColumn.filter.text && row[filterableColumn.name] < filterableColumn.filter.argument[0]);
                break;
            default:
                throw 'Unsupported Compare Operator';
        }
    });
github unosquare / tubular-nodejs / src / connectors / jsondata.spec.js View on Github external
it("filters using Between", done => {
            const take = 10,
                filteredCount = 48;

            let request = new GridRequest(
                [
                    { name: 'first_name', label: 'First Name', sortable: true, searchable: true },
                    { name: 'last_name', label: 'Last Name', sortable: true, searchable: true },
                    {
                        name: 'address_id', label: 'Address Id', sortable: true, searchable: false, filter: {
                            name: '',
                            text: 1,
                            argument: [50],
                            operator: CompareOperators.Between,
                            hasFilter: false
                        }
                    }
                ],
                take,
                0,
            );

            tubular.createGridResponse(request, data)
                .then(response => {
                    expect(response.counter).toBeDefined();
                    expect(response.totalRecordCount).toBe(totalRecordCount);
                    expect(response.filteredRecordCount).toBe(filteredCount);
                    expect(response.totalPages).toBe(Math.ceil(filteredCount / take));
                    expect(response.payload.length).toBe(10);
                    done();
github unosquare / tubular-nodejs / src / connectors / knex.spec.js View on Github external
it("filters using Between", done => {
            const take = 10,
                filteredCount = 597;

            let request = new GridRequest(
                [
                    { name: 'first_name', label: 'First Name', sortable: true, searchable: true },
                    { name: 'last_name', label: 'Last Name', sortable: true, searchable: true },
                    {
                        name: 'customer_id', label: 'Customer Id', sortable: true, searchable: false, filter: {
                            name: '',
                            text: 2,
                            argument: [598],
                            operator: CompareOperators.Between,
                            hasFilter: false
                        }
                    }
                ],
                take,
                0,
            );

            let queryBuilder = knex.select('first_name', 'last_name', 'customer_id').from('customer');

            tubular.createGridResponse(request, queryBuilder)
                .then(response => {
                    expect(response.counter).toBeDefined();
                    expect(response.totalRecordCount).toBe(totalRecordCount);
                    expect(response.filteredRecordCount).toBe(filteredCount);
                    expect(response.totalPages).toBe(Math.ceil(filteredCount / take));
github unosquare / tubular-nodejs / src / connectors / knex.js View on Github external
case CompareOperators.NotStartsWith:
                subset = subset.whereNot(filterableColumn.name, 'LIKE', `${filterableColumn.filter.text}%`);
                break;
            case CompareOperators.EndsWith:
                subset = subset.where(filterableColumn.name, 'LIKE', `%${filterableColumn.filter.text}`);
                break;
            case CompareOperators.NotEndsWith:
                subset = subset.whereNot(filterableColumn.name, 'LIKE', `%${filterableColumn.filter.text}`);
                break;
            case CompareOperators.Gt:
            case CompareOperators.Gte:
            case CompareOperators.Lt:
            case CompareOperators.Lte:
                subset = subset.where(filterableColumn.name, getCompareOperators(filterableColumn.filter.operator), filterableColumn.filter.text);
                break;
            case CompareOperators.Between:
                subset = subset.whereBetween(filterableColumn.name, [filterableColumn.filter.text, filterableColumn.filter.argument[0]]);
                break;
            default:
                throw 'Unsupported Compare Operator';
        }
    });