Node.js datatables editor - Filter select option depending on a certain value

Node.js datatables editor - Filter select option depending on a certain value

CapamaniaCapamania Posts: 229Questions: 79Answers: 5
edited January 2019 in Editor

I'm using the node.js datatable editor library. When trying to filter the select options depending on a specific user_id ... I'm getting TypeError: this.where is not a function

I already posted the issue on SO ... https://stackoverflow.com/questions/54012451/node-js-datatables-editor-filter-select-option-depending-on-a-certain-value

How do I get to filter the option values in editor for node.js?

This question has an accepted answers - jump to answer

Answers

  • CapamaniaCapamania Posts: 229Questions: 79Answers: 5

    Any thought why this not works? How do I get to filter the option values in editor for node.js?

    node.js

        let editor = new Editor( db, 'portfolios_isin_mm' )
            .fields(
                new Field( 'portfolios_isin_mm.account_id' ),
                new Field( 'portfolios_isin_mm.user_id' ),
                new Field( 'portfolios_isin_mm.uid_foreign' )
                    .options(new Options()
                        .table('portfolios_isin')
                        .value('id')
                        .label('portfolio_name')
                        .where(() => {
                            this.where('user_id', '=', '1')
                        })
                    ),
                new Field( 'securities.issuer_name' )
            )
            
            .leftJoin( 'portfolios_isin', 'portfolios_isin.id', '=', 'portfolios_isin_mm.uid_foreign' )
    

    I'm getting this Error:

        TypeError: this.where is not a function
            at Builder.Editor.fields.Field.options.Options.table.value.label.where (/home/project/controllers/quey.js:359:30)
            at Formatter.compileCallback (/home/project/node_modules/knex/lib/formatter.js:161:14)
            at Formatter.rawOrFn (/home/project/node_modules/knex/lib/formatter.js:104:36)
            at QueryCompiler_MySQL.whereWrapped (/home/project/node_modules/knex/lib/query/compiler.js:531:30)
            at QueryCompiler_MySQL.where (/home/project/node_modules/knex/lib/query/compiler.js:314:32)
            at /home/project/node_modules/knex/lib/query/compiler.js:147:30
            at Array.map (<anonymous>)
            at QueryCompiler_MySQL.select (/home/project/node_modules/knex/lib/query/compiler.js:146:33)
            at QueryCompiler_MySQL.toSQL (/home/project/node_modules/knex/lib/query/compiler.js:108:27)
            at Builder.toSQL (/home/project/node_modules/knex/lib/query/builder.js:115:44)
            at /home/project/node_modules/knex/lib/runner.js:56:32
            at tryCatcher (/home/project/node_modules/bluebird/js/release/util.js:16:23)
            at /home/project/node_modules/bluebird/js/release/using.js:185:26
            at tryCatcher (/home/project/node_modules/bluebird/js/release/util.js:16:23)
            at Promise._settlePromiseFromHandler (/home/project/node_modules/bluebird/js/release/promise.js:512:31)
            at Promise._settlePromise (/home/project/node_modules/bluebird/js/release/promise.js:569:18)
    

    According to the docs https://editor.datatables.net/manual/nodejs/joins this is the way to do it. I have a similar project where I use the php datatable editor libraries ... there I can do the same this just fine like this:

    php:

        Editor::inst( $db, 'portfolios_isin_mm' )
            ->fields(
                Field::inst( 'portfolios_isin_mm.account_id' ),
                Field::inst( 'portfolios_isin_mm.user_id' ),
                Field::inst( 'portfolios_isin_mm.uid_foreign' )
                    ->options( 'portfolios_isin', 'id', 'portfolio_name', function ($q) {
                        $q->where( 'portfolios_isin.user_id', '1', '=' );
                    }),
                Field::inst( 'securities.issuer_name' )         
            )
            
            ->leftJoin( 'portfolios_isin', 'portfolios_isin.id', '=', 'portfolios_isin_mm.uid_foreign' )    
    

    How do I get to filter the option values in editor for node.js?

  • allanallan Posts: 61,446Questions: 1Answers: 10,054 Site admin
    Answer ✓

    Try the following please:

                    .where((q) => {
                        q.where('user_id', '=', '1')
                    })
    

    I think there is an issue with versioning and the docs there.

    Allan

  • CapamaniaCapamania Posts: 229Questions: 79Answers: 5

    Great ... this part is working again. Thanks

This discussion has been closed.