How to sort columns on server side
How to sort columns on server side
We have a situation where i have 5 columns in the data table on a server side request, based on the users permissions we hide and show various columns based on their permission levels.
For instance an admin user can see all the columns [ AcctName, AcctPwd, DateCreated, LastUpdated, LastLogin]. For a normal user can we do not allow them to see the password column so they only see [AcctName, DateCreated, LastUpdated, LastLogin] and AcctPwd visible: false
When the user clicks on the sort column icon in the data table, we get the form values. We look for order[0][column] and order[0][dir] and then sort the data appropiately on the server side like your documention suggest.
However depending on the view the server_side is getting a 1 when the admin user clicks on AcctPwd, and we also get a 1 when the regular user clicks on the DateCreated column, and the column index is off from every other visible column after that. How can the server_side know which column 1 is actually pointing to? Is there a way we can get the column name on the server side to know they click on the AcctPwd or DateCreated column?
This also presents a problem when we change the JavaScript column order and forget to update the server_side ordering, having a name would be a hugh help, right now I really cannot sort the column data server_side without knowing the correct column.
Any help would be appreciated.
Answers
Hi,
order[0][column]
will give you the index of the column which is being sorted upon. You can then look that index up in the submittedcolumns
array to determine what the column is.The
columns[i]
array contains adata
property which is the value ofcolumns.data
from the client-side if you are using that (e.g.AcctName
). Optionally you can also usecolumns.name
to assign your own name to a column which will also be sent as part of thecolumns[i]
data.Allan
This is what we are doing, but as I stated the column being sorting is sending the wrong index number due columns before it having visible:false set. Meaning if i have volumns 1, 2, 3, 4, I sort column 4, it send 4, if i hide columns 2,3 and click on 4 to sort it sends a 2 instead of 4, how do we determine which is the real column being clicked, the 2 or 4? I want to see 4 to know that is the column they want to sort. When you dynamically show and hide columns it makes it impossible to get know on the server side, any help would be appreciated.
The columns and columns[i] always returns null on the server side do you have an example we can try?
I'm not seeing that in this example . There, if you look at the network inspector, the full data is being sent, even for those columns that aren't visible. Could you look at that, please, and see if it helps. If it's still not working for you, please can you update my example, or link to your page, so that we can see the problem.
Cheers,
Colin
We found a working solution, thanks.