Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Same output for all Query Builder #19

Open
nikunj-digicorp opened this issue Mar 7, 2017 · 6 comments · May be fixed by #23
Open

Same output for all Query Builder #19

nikunj-digicorp opened this issue Mar 7, 2017 · 6 comments · May be fixed by #23

Comments

@nikunj-digicorp
Copy link

nikunj-digicorp commented Mar 7, 2017

I'm getting same output for all the method calls from generate.js, am I missing anything?

Called 1
Queries:
{"recordsTotal":"SELECT COUNT(id) FROM Orgs","select":"SELECT * FROM Orgs"}
Called 2
Queries:
{"recordsTotal":"SELECT COUNT(id) FROM Orgs","select":"SELECT * FROM Orgs"}
Called 3
Queries:
{"recordsTotal":"SELECT COUNT(id) FROM Orgs","select":"SELECT * FROM Orgs"}
Called 4
Queries:
{"recordsTotal":"SELECT COUNT(id) FROM Orgs","select":"SELECT * FROM Orgs"}

@nikunj-digicorp
Copy link
Author

Is there any working demo available on git that support MySQL and JQuery DataTable?
Can you please help me to short out this?
Thanks in Advance! 👍
BTW, The code is nicely managed.

@jpravetz
Copy link
Owner

jpravetz commented Mar 8, 2017

It's been awhile since I worked with SQL. I'd have to spend more time than I have to look at your first message. Sorry. Also, the only example I had was proprietary, so I can't share it (and it was quite complex).

@nikunj-digicorp
Copy link
Author

Thank you for answer.

@thbl
Copy link

thbl commented Jun 1, 2017

got the same error, did you find out how to use it ?

@ghybs
Copy link

ghybs commented Mar 6, 2018

Hi,

FWIW, in order to have ORDER and WHERE / SEARCH being correctly taken into account, make sure to define your columns specifying their name as well, as mentioned in #14 (comment).

In my version of DataTables (not sure if behaviour changed at some point), the data / requestQuery parameter passed by DataTables to the ajax function option also had columns' orderable and searchable options defined as boolean's, whereas node-datatable compares them strictly with string values:

if (column.orderable === 'true' && column.name) {

if (customColumns || column.searchable === 'true'){

If you are in that case, you have to convert these fields first into strings before passing the refactored requestQuery to buildQuery() method.

I had no problem at all regarding the PARTIAL / LIMIT query.

Hope this helps.

@ghybs
Copy link

ghybs commented Mar 7, 2018

Live demo of this bug: https://plnkr.co/edit/auaYxFKq1bOVU4IhcP2T?p=preview

An example of workaround:

function formatRequestQuery(requestQuery) {
  requestQuery.columns.forEach(function(column) {
    formatColumnField(column, 'orderable');
    formatColumnField(column, 'searchable');
  });

  return requestQuery;
}

function formatColumnField(column, fieldName) {
  if (typeof column[fieldName] === 'boolean') {
    column[fieldName] = column[fieldName] ? 'true' : 'false'
  }
}

Use it to refactor the requestQuery before passing it to queryBuilder.buildQuery() method.

See it in action: https://plnkr.co/edit/PZiw9h5z0AgqSAQIfcXM?p=preview

@ghybs ghybs linked a pull request Mar 7, 2018 that will close this issue
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants