Select filters moving along columns
Select filters moving along columns
I'm using select filters with columns that can be hidden, but this is causing them to move along when the columns are toggled off. I'm guessing the problem is with the function buildSelect .columns([1,2])
. The select filters move to columns 3 and 4 when the Toggle Columns button Position/Office is clicked (which hides both columns). I tried using column names but that didn't work. Is it possible to stop this happening? http://live.datatables.net/pusaxiyu/1/edit
This question has accepted answers - jump to:
Answers
Does this thread help? Its a similar question you asked before.
Kevin
It's funny you should mentioned that Kevin! I'd already referred back to that version which does work fine on my local dev and your test case. However, when I tried to get it working with this different version I didn't have any luck. I thought it might be down to the different way of hiding columns and not using
colvis
. I've added that code back in the test case to show it doesn't seem to work. http://live.datatables.net/pusaxiyu/1/edit. Does anything look wrong to you?Here is a little update to your code, but I'm not sure it is exactly what you are looking for: http://live.datatables.net/pusaxiyu/4/edit .
In it the Position and Office columns are the only ones with
select
filters - is that what you want. When they are hidden, the filters go as well.The key thing here is to know that DataTables doesn't support multiple
thead
elements like you had in your HTML. It simply doesn't keep track of any but the first. So you need to have a singlethead
, but it can have multiple rows.Allan
Sorry about the multiple thead Allan. They weren't in my dev version so I must've overlooked them whilst testing. Your version does function like I was expecting it to. The filters are hidden when the columns are hidden and the cascading filtering works too.
However, my dev version is different which might be causing the problems. It's based on a tutorial I followed to pull a CSV in using Ajax. Up to now it's worked fine with the different versions of DT I've done so I think the code structure is OK, but you might tell me otherwise. The placing of this code gives different results...
I've added comments above the 2 locations I've tried this code, and what the results were. Can you spot anything wrong with this simplified edited code?
Drop all of your calls to
buildSelect
other than that ininitComplete
. You shouldn't need to regenerate the select dropdowns.Allan
Hi Allan. I've done that and now the cascading doesn't work.
buildSelect( table );
on line 98 does call the function and that works, it's just then the filters on column hiding move to the next 2 columns.I removed the second
thead
from your example as Allan noted and addedorderCellsTop
. Since you aren't looping through all the columns to update the selects you first need to remove all of them, my example uses this code:You then need to use
column.index('visible');
to get the proper index to apply the select input:I also added another toggle group for
Name
to see this work.http://live.datatables.net/pusaxiyu/5/edit
Kevin
Hi Kevin. I've just looked at your test case but if "Position/Office" is toggled off the Office filter moves over to the top of the Name column. Cascading still seems to work though.
Ok. so if the column isn't visible then the
column.index('visible');
isnull
. I added an if statement to test for this:http://live.datatables.net/pusaxiyu/6/edit
Kevin
Unfortunately filters are still moving around the columns. I did have a working version of this from a few weeks ago which you kindly helped with. The main difference with this version though, is the toggling of multiple columns at once which seems to be the sticking point. This version extends columnToggle whereas the single column toggle used colvis which worked fine.
Are you saying that my example has this problem? If so please provide the steps to recreate.
I forgot to mention that I changed the toggle groups to pair position with age and office with start date to show this a bit better.
Kevin
I added back your original toggle pairs along with mine:
http://live.datatables.net/pusaxiyu/7/edit
Updated example:
https://live.datatables.net/pusaxiyu/66/edit
Kevin
Ah, that's why I thought they were jumping around a bit!
I've just transferred your changes to my dev version and after initial testing it all looks OK. Thank you very much for getting to the bottom of the problem again Kevin!