How to use the tubular-common.CompareOperators.Contains 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.spec.js View on Github external
it(" filters by one column", done => {
            const take = 10,
                filteredCount = 1;

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

            tubular.createGridResponse(request, data)
                .then(response => {
                    expect(response.counter).toBeDefined();
                    expect(response.totalRecordCount).toBe(totalRecordCount);
                    expect(response.filteredRecordCount).toBe(filteredCount);
github unosquare / tubular-nodejs / src / connectors / knex.spec.js View on Github external
it(" filters by one column", done => {
            const take = 10,
                filteredCount = 1;

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


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

            tubular.createGridResponse(request, queryBuilder)
                .then(response => {
                    expect(response.counter).toBeDefined();
                    expect(response.totalRecordCount).toBe(totalRecordCount);
                    expect(response.filteredRecordCount).toBe(filteredCount);
github unosquare / tubular-nodejs / src / connectors / jsondata.spec.js View on Github external
it("filters using Contains", done => {
            const take = 10,
                filteredCount = 2;

            let request = new GridRequest(
                [
                    {
                        name: 'first_name', label: 'First Name', sortable: true, searchable: true, filter: {
                            name: '',
                            text: 'ley',
                            argument: [],
                            operator: CompareOperators.Contains,
                            hasFilter: false
                        }
                    },
                    { name: 'last_name', label: 'Last Name', sortable: true, searchable: true },
                    { name: 'address_id', label: 'Address Id', sortable: true, searchable: 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));
github unosquare / tubular-nodejs / src / connectors / knex.spec.js View on Github external
it("filters using Contains", done => {
            const take = 10,
                filteredCount = 5;

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

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

            tubular.createGridResponse(request, queryBuilder)
                .then(response => {
                    expect(response.counter).toBeDefined();
                    expect(response.totalRecordCount).toBe(totalRecordCount);
github unosquare / tubular-nodejs / src / connectors / jsondata.js View on Github external
filteredColumns.forEach(filterableColumn => {

        request.columns.find(column => column.name == filterableColumn.name).hasFilter = true;

        switch (filterableColumn.filter.operator) {
            case CompareOperators.Equals:
                subset = subset.filter(row => row[filterableColumn.name] == filterableColumn.filter.text);
                break;
            case CompareOperators.NotEquals:
                subset = subset.filter(row => row[filterableColumn.name] != filterableColumn.filter.text);
                break;
            case CompareOperators.Contains:
                subset = subset.filter(row => row[filterableColumn.name].indexOf(filterableColumn.filter.text) >= 0);
                break;
            case CompareOperators.NotContains:
                subset = subset.filter(row => row[filterableColumn.name].indexOf(filterableColumn.filter.text) < 0);
                break;
            case CompareOperators.StartsWith:
                subset = subset.filter(row => row[filterableColumn.name].toLowerCase().startsWith(filterableColumn.filter.text));
                break;
            case CompareOperators.NotStartsWith:
                subset = subset.filter(row => !row[filterableColumn.name].toLowerCase().startsWith(filterableColumn.filter.text));
                break;
            case CompareOperators.EndsWith:
                subset = subset.filter(row => row[filterableColumn.name].toLowerCase().endsWith(filterableColumn.filter.text));
                break;
            case CompareOperators.NotEndsWith:
                subset = subset.filter(row => !row[filterableColumn.name].toLowerCase().endsWith(filterableColumn.filter.text));
github unosquare / tubular-nodejs / src / connectors / knex.js View on Github external
filteredColumns.forEach(filterableColumn => {
        request.columns.find(column => column.name == filterableColumn.name).HasFilter = true;

        switch (filterableColumn.filter.operator) {
            case CompareOperators.Equals:
                subset = subset.where(filterableColumn.name, filterableColumn.filter.text);
                break;
            case CompareOperators.NotEquals:
                subset = subset.whereNot(filterableColumn.name, filterableColumn.filter.text);
                break;
            case CompareOperators.Contains:
                subset = subset.where(filterableColumn.name, 'LIKE', `%${filterableColumn.filter.text}%`);
                break;
            case CompareOperators.NotContains:
                subset = subset.whereNot(filterableColumn.name, 'LIKE', `%${filterableColumn.filter.text}%`);
                break;
            case CompareOperators.StartsWith:
                subset = subset.where(filterableColumn.name, 'LIKE', `${filterableColumn.filter.text}%`);
                break;
            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}`);