Reading values from search pane options
Reading values from search pane options
Hi ,
I am writing a function to change the table headers based on the drop down list in global filter.
For example, if the value USA
is chosen in drop down menu the six headings will be 'A', 'B', 'C', 'D', ' ', ' '
and if the value UK
is chosen in drop down menu the six headings will be> 'E' , 'F', 'G', 'H', 'I,', 'J '
function headerChange() {
var target = $('#global_filter option:selected').val();
if(target == "USA"){
$( table.column(0).header() ).html('A');
$( table.column(1).header() ).html('B');
$( table.column(2).header() ).html('C');
$( table.column(3).header() ).html(D'');
$( table.column(4).header() ).html('');
$( table.column(5).header() ).html('');
}
else if(target == "UK"){
$( table.column(0).header() ).html('E');
$( table.column(1).header() ).html('F');
$( table.column(2).header() ).html('G');
$( table.column(3).header() ).html('H');
$( table.column(4).header() ).html('I');
$( table.column(5).header() ).html('J');
}
}
Then I call this inside global filter
$('#global_filter').on( 'keyup click', function () {
filterGlobal();
headerChange();
});
I want something similar , like this var target = $('#global_filter option:selected').val();
to select values from searchPane
and the use the same logic to chnage table headers.
Also, can I hide the columns based on the logic, if table header is empty.
for example, if I choosetarget = "USA"
, table header names for $( table.column(4) and $( table.column(5)
are empty.
Can I use some logic to hide these last two columns based on the logic, if these are empty?
This question has an accepted answers - jump to answer
Answers
Yep, you can hide columns programmatically with
column().visible()
andcolumns().visible()
,Colin
@colin
I manged to hide the columns with empty header using
"fnDrawCallback": function () {
With regards to
How can I access values from SearchPane?
Hi @Khalid Teli ,
Take a look at this post discussing a similar issue, it should answer your question.
Thanks,
Sandy
@sandy
Thank you.
Thanks is what I was looking for.
Rather than using
$('#selections').on('click', function(){
i used$('.dtsp-nameColumn')
but it wont give dispay anything on click? I dont know whyI changed it on thsi example http://live.datatables.net/runawara/1/edit it works on double click but in my own code it doesnt
Hi @Khalid Teli ,
That is because the click event is running before SearchPanes has changed the selections. Take a look at this example that listens for the
select
.Thanks,
Sandy
@sandy
Thank you, the example you provided is perfect, It is exactly doing what I want. However, when I use the same in my code it doesn't work.
When using the bvutton click event, it works fine
Try changing your select event to use
select.dt
, for example:Kevin
@kthorngren
Thank you! I tried using this but still not working
Since you are using
ajax
you might need to move the code intoinitComplete
so its not executed until after Datatables initializes.Kevin
@kthorngren
Thank you. That worked