Custom Column Order & Visibility
Custom Column Order & Visibility
Ironwil616
Posts: 50Questions: 0Answers: 0
Ideally, what I want to do is set the visibility and order of the columns in my table at runtime. I do not want to do this via server-side code. It's also not an option to send this data to the server for a SQL query. The list of objects that populates my table aren't simple database objects. I have to aggregate data from multiple tables and resolve this at runtime. Custom views are created at runtime, so this won't be static.
What I need to do is take in a list of columns and render them in that order. All columns not in the list should not be visible at all. Rewriting my server code to return this dynamically isn't a viable option for me now. I just want to return the complete table, and set order and visibility based on the list of columns in the datatable options. Is this possible to do?
What I need to do is take in a list of columns and render them in that order. All columns not in the list should not be visible at all. Rewriting my server code to return this dynamically isn't a viable option for me now. I just want to return the complete table, and set order and visibility based on the list of columns in the datatable options. Is this possible to do?
This discussion has been closed.
Replies
[code]
$(document).ready(function () {
var oTable = $('#example').dataTable({
"sDom": 'Rlfrtip',
"oColReorder": {
"aiOrder": [0 , 4, 3, 2, 1]
},
"aoColumnDefs": [
{ "bVisible": false, "aTargets": [3] }
]});
});
[/code]
My table has a possible 28 columns, so I just used this combination of examples from the website. I've tested them together, and they work as expected. I read that 'aoColumnDefs' are supposed to be able to accept a string as well as an integer index, and I thought that meant that 'aTargets' would accept the string. This didn't seem to be the case. Having the columns accessible by table head cell values would be better than integer indexes, and maybe I just haven't found the correct means yet. I'll look over it more tomorrow. At the very least, I have a workable solution, which is great, as time is critical right now.
Good to hear you got a workaround for now with ColReorder though :-)
Regards,
Allan