Issues with ServerSide conditions not being persistent
Issues with ServerSide conditions not being persistent
I'm trying to create a script to support serverSide
in NodeJS/ExpressJS/SequelizeJS, and first id like to say, that even though I have plenty of experience in PHP/MySQL/Apache/CodeIgniter/jQuery, I'm very new to Node/Express/Sequelize.. So please excuse the terrible code you're about to see. This is actually my first NodeJS project, ever... other than the typical Hello World kinda stuff.
So basically, I'm writing the code for the conditions one at a time. I started with the pagination (start
) and length
, then ordering, while reading the Server Side manual
Heres the GitHub repo, the main file is the app.js, and the Sequelize model is the models/SSP.js.
Line $56 in the app.js file is for http requests to /ssp, which is where the ajax
is set to, and you can see on Line #58, I output the entire query sent by DataTables, this is whats processed into a query.
The issue is, when I click on a pagination link, which sets the start
to 10, (which works fine), then order a column, it looks like the start
value gets reset.. shouldn't DataTables keep the start
value when a column gets re-ordered?
Heres the JSON data that is received, you can see in the comments, the first one is the initial load, the 2nd one is when I click on the 2nd pagination link (Setting start
to 10), the 3rd one is when I click on the Extn column, which orders column index #3, but notice that the start
gets set back to 0...
/*
* FIRST query - Initial page load
*/
{ draw: '1',
columns:
[ { data: '0',
name: '',
searchable: 'true',
orderable: 'true',
search: [Object] },
{ data: '1',
name: '',
searchable: 'true',
orderable: 'true',
search: [Object] },
{ data: '2',
name: '',
searchable: 'true',
orderable: 'true',
search: [Object] },
{ data: '3',
name: '',
searchable: 'true',
orderable: 'true',
search: [Object] },
{ data: '4',
name: '',
searchable: 'true',
orderable: 'true',
search: [Object] },
{ data: '5',
name: '',
searchable: 'true',
orderable: 'true',
search: [Object] } ],
order: [ { column: '0', dir: 'asc' } ],
start: '0',
length: '10',
search: { value: '', regex: 'false' },
_: '1449783776050' }
/*
* SECOND query - Clicked on pagination link for page #2
*/
{ draw: '2',
columns:
[ { data: '0',
name: '',
searchable: 'true',
orderable: 'true',
search: [Object] },
{ data: '1',
name: '',
searchable: 'true',
orderable: 'true',
search: [Object] },
{ data: '2',
name: '',
searchable: 'true',
orderable: 'true',
search: [Object] },
{ data: '3',
name: '',
searchable: 'true',
orderable: 'true',
search: [Object] },
{ data: '4',
name: '',
searchable: 'true',
orderable: 'true',
search: [Object] },
{ data: '5',
name: '',
searchable: 'true',
orderable: 'true',
search: [Object] } ],
order: [ { column: '0', dir: 'asc' } ],
start: '10',
length: '10',
search: { value: '', regex: 'false' },
_: '1449783776051' }
/*
* THIRD Query - Clicked on column index #3
*/
{ draw: '3',
columns:
[ { data: '0',
name: '',
searchable: 'true',
orderable: 'true',
search: [Object] },
{ data: '1',
name: '',
searchable: 'true',
orderable: 'true',
search: [Object] },
{ data: '2',
name: '',
searchable: 'true',
orderable: 'true',
search: [Object] },
{ data: '3',
name: '',
searchable: 'true',
orderable: 'true',
search: [Object] },
{ data: '4',
name: '',
searchable: 'true',
orderable: 'true',
search: [Object] },
{ data: '5',
name: '',
searchable: 'true',
orderable: 'true',
search: [Object] } ],
order: [ { column: '3', dir: 'asc' } ],
start: '0',
length: '10',
search: { value: '', regex: 'false' },
_: '1449783776052' }
Any help is appreciated! Thanks
This question has an accepted answers - jump to answer
Answers
@allan, do you see what im doing wrong?
FYI, Git repo has changed, SSP Model is at /src/models/SSP.js, and the app.js was moved to /src/app.jsx
The changes werent to resolve the error though, it still persists.
Hm.. so after looking at the other examples, like the basic SSP example, and even the zero config, they all do that...
I thought that if you go to page two, then sort by a column... you would still be at page two... Is this supposed to be like this?.. Really weird
EDIT: Nevermind on this post, I was wondering why the PHP config for the server side example needed the
dt
element, since they are all just integers, thus the elements index would suffice, but I realize that if you specify thecolumns.data
, you would need to use the names instead of the indexesNice monologue ;-). Good to hear you got it sorted.
Allan
@allan, shouldnt the pagination kewp, when a column is sorted? It seems wrong that it doesn't, though i see it foes that for all demos
My thought process on this was: if I sort on a column, why would I want to be in the middle of the data set, which might have no relation to the page that I was on previously. At least if it resets to the start of the data set you'll be able to anchor your position and get your bearings quickly. Likewise with filtering.
Allan
Thats exactly what I thought your thought process was.. haha
Thanks for clarifying!