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












0















I'm using the node.js datatable editor library. When trying to filter the select options depending on a specific field (user_id) in table 'portfolios_isin' like this:



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')
this.where('portfolios_isin.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/myproject.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 (and all is working just fine) ... there I can filter the options 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?










share|improve this question

























  • What version of node are you using?

    – Jeff Breadner
    Jan 2 at 20:43











  • $ node -v ... v10.15.0

    – Philipp M
    Jan 2 at 20:45











  • Is the code you've shown server side or client side?

    – Jeff Breadner
    Jan 2 at 20:49











  • The editor node.js libraries are serverside ... the error message also.

    – Philipp M
    Jan 2 at 20:51
















0















I'm using the node.js datatable editor library. When trying to filter the select options depending on a specific field (user_id) in table 'portfolios_isin' like this:



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')
this.where('portfolios_isin.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/myproject.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 (and all is working just fine) ... there I can filter the options 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?










share|improve this question

























  • What version of node are you using?

    – Jeff Breadner
    Jan 2 at 20:43











  • $ node -v ... v10.15.0

    – Philipp M
    Jan 2 at 20:45











  • Is the code you've shown server side or client side?

    – Jeff Breadner
    Jan 2 at 20:49











  • The editor node.js libraries are serverside ... the error message also.

    – Philipp M
    Jan 2 at 20:51














0












0








0








I'm using the node.js datatable editor library. When trying to filter the select options depending on a specific field (user_id) in table 'portfolios_isin' like this:



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')
this.where('portfolios_isin.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/myproject.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 (and all is working just fine) ... there I can filter the options 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?










share|improve this question
















I'm using the node.js datatable editor library. When trying to filter the select options depending on a specific field (user_id) in table 'portfolios_isin' like this:



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')
this.where('portfolios_isin.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/myproject.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 (and all is working just fine) ... there I can filter the options 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?







javascript node.js datatables jquery-datatables-editor






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited Jan 3 at 9:29







Philipp M

















asked Jan 2 at 20:02









Philipp MPhilipp M

8421929




8421929













  • What version of node are you using?

    – Jeff Breadner
    Jan 2 at 20:43











  • $ node -v ... v10.15.0

    – Philipp M
    Jan 2 at 20:45











  • Is the code you've shown server side or client side?

    – Jeff Breadner
    Jan 2 at 20:49











  • The editor node.js libraries are serverside ... the error message also.

    – Philipp M
    Jan 2 at 20:51



















  • What version of node are you using?

    – Jeff Breadner
    Jan 2 at 20:43











  • $ node -v ... v10.15.0

    – Philipp M
    Jan 2 at 20:45











  • Is the code you've shown server side or client side?

    – Jeff Breadner
    Jan 2 at 20:49











  • The editor node.js libraries are serverside ... the error message also.

    – Philipp M
    Jan 2 at 20:51

















What version of node are you using?

– Jeff Breadner
Jan 2 at 20:43





What version of node are you using?

– Jeff Breadner
Jan 2 at 20:43













$ node -v ... v10.15.0

– Philipp M
Jan 2 at 20:45





$ node -v ... v10.15.0

– Philipp M
Jan 2 at 20:45













Is the code you've shown server side or client side?

– Jeff Breadner
Jan 2 at 20:49





Is the code you've shown server side or client side?

– Jeff Breadner
Jan 2 at 20:49













The editor node.js libraries are serverside ... the error message also.

– Philipp M
Jan 2 at 20:51





The editor node.js libraries are serverside ... the error message also.

– Philipp M
Jan 2 at 20:51












1 Answer
1






active

oldest

votes


















1














this.where is out of the scope where the function where exist, because you are using an arrow function which binds this to the outer/parent scope.



Try this instead:



.options(new Options()
.table('portfolios_isin')
.value('id')
.label('portfolio_name')
.where(function(){
this.where('portfolios_isin.user_id', '=', '1')
})
),





share|improve this answer
























  • thanks ... do you happen to know also how to retrieve unique values? stackoverflow.com/questions/54154572/…

    – Philipp M
    Jan 12 at 10:43












Your Answer






StackExchange.ifUsing("editor", function () {
StackExchange.using("externalEditor", function () {
StackExchange.using("snippets", function () {
StackExchange.snippets.init();
});
});
}, "code-snippets");

StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "1"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);

StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});

function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});


}
});














draft saved

draft discarded


















StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f54012451%2fnode-js-datatables-editor-filter-select-option-depending-on-a-certain-value%23new-answer', 'question_page');
}
);

Post as a guest















Required, but never shown

























1 Answer
1






active

oldest

votes








1 Answer
1






active

oldest

votes









active

oldest

votes






active

oldest

votes









1














this.where is out of the scope where the function where exist, because you are using an arrow function which binds this to the outer/parent scope.



Try this instead:



.options(new Options()
.table('portfolios_isin')
.value('id')
.label('portfolio_name')
.where(function(){
this.where('portfolios_isin.user_id', '=', '1')
})
),





share|improve this answer
























  • thanks ... do you happen to know also how to retrieve unique values? stackoverflow.com/questions/54154572/…

    – Philipp M
    Jan 12 at 10:43
















1














this.where is out of the scope where the function where exist, because you are using an arrow function which binds this to the outer/parent scope.



Try this instead:



.options(new Options()
.table('portfolios_isin')
.value('id')
.label('portfolio_name')
.where(function(){
this.where('portfolios_isin.user_id', '=', '1')
})
),





share|improve this answer
























  • thanks ... do you happen to know also how to retrieve unique values? stackoverflow.com/questions/54154572/…

    – Philipp M
    Jan 12 at 10:43














1












1








1







this.where is out of the scope where the function where exist, because you are using an arrow function which binds this to the outer/parent scope.



Try this instead:



.options(new Options()
.table('portfolios_isin')
.value('id')
.label('portfolio_name')
.where(function(){
this.where('portfolios_isin.user_id', '=', '1')
})
),





share|improve this answer













this.where is out of the scope where the function where exist, because you are using an arrow function which binds this to the outer/parent scope.



Try this instead:



.options(new Options()
.table('portfolios_isin')
.value('id')
.label('portfolio_name')
.where(function(){
this.where('portfolios_isin.user_id', '=', '1')
})
),






share|improve this answer












share|improve this answer



share|improve this answer










answered Jan 12 at 0:42









Paul OkekePaul Okeke

7581916




7581916













  • thanks ... do you happen to know also how to retrieve unique values? stackoverflow.com/questions/54154572/…

    – Philipp M
    Jan 12 at 10:43



















  • thanks ... do you happen to know also how to retrieve unique values? stackoverflow.com/questions/54154572/…

    – Philipp M
    Jan 12 at 10:43

















thanks ... do you happen to know also how to retrieve unique values? stackoverflow.com/questions/54154572/…

– Philipp M
Jan 12 at 10:43





thanks ... do you happen to know also how to retrieve unique values? stackoverflow.com/questions/54154572/…

– Philipp M
Jan 12 at 10:43




















draft saved

draft discarded




















































Thanks for contributing an answer to Stack Overflow!


  • Please be sure to answer the question. Provide details and share your research!

But avoid



  • Asking for help, clarification, or responding to other answers.

  • Making statements based on opinion; back them up with references or personal experience.


To learn more, see our tips on writing great answers.




draft saved


draft discarded














StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f54012451%2fnode-js-datatables-editor-filter-select-option-depending-on-a-certain-value%23new-answer', 'question_page');
}
);

Post as a guest















Required, but never shown





















































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown

































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown







Popular posts from this blog

MongoDB - Not Authorized To Execute Command

in spring boot 2.1 many test slices are not allowed anymore due to multiple @BootstrapWith

How to fix TextFormField cause rebuild widget in Flutter