why are my queries doubled when fixedColumns is being used?
why are my queries doubled when fixedColumns is being used?
I don't know if this is directly related to datatables, but I suspect that I am doing something wrong here.
In the following live page:
http://live.datatables.net/rojulesi/1/edit
I have a simple table with 2 rows, and three data columns. The first column has a checkbox, and that is my problem.
Each of the other columns has checkboxes in their headers too, but right now I am grappling with the checkboxes in the rows.
So here is the problem:
My row checkboxes have a class name of rowcb so that I can query them. When I query the checkboxes, I get 4 of them (they come back twice).
That jquery call is var allrowcbs = $('.rowcb');
As a sanity check, the next column over has a class name of firstrealcolumn, and when I query them, I get back 2 of them like I would expect.
That jquery call is var firstrealcolumnlist = $('.firstrealcolumn');
After working with this for a while, I noticed that my checkbox column is in the fixedColumn range (and it is the only one in this case, so rowcb is fixed, and firstrealcolumn is not). Sure enough, when I set fixedColumns leftColumns to 0, my queries work correctly.
So how to I get around this? How do I query the checkboxes that are actually being set? I suspect there is a hidden set under the fixedcolumn panel that are not set, and of course I do not want those.
Replies
The issue here is that you are using FixedColumns. The way FixedColumns works is to clone the cells of the columns that are to be fixed and then display them statically above the table. This is why you will always get exactly twice the number of input elements if you use them in a fixed column.
That could be overcome by using a more refined selector, but because the reclone will happen on each draw event, the checked status of the inputs in the FixedColumns (i.e. the ones the user will interact with) will be lost and replaced with new clones.
It would be possible to propagate the checked state to the checkboxes which are hidden, but that seems really messy.
An alternative might be to use something like Select to do the checkboxes.
Allan
Unfortunately, using the Select renders a style that is different from the checkboxes I am already using in the column headers. I'm afraid that I am stuck with these checkboxes.
Every time a checkbox is selected or unselected, I track this in an array, so I have all the data I need to set checkboxes. I just need to find the ones that are cloned, after they are cloned, and set them.
Hi,
I've sent a reply to your e-mail on this topic.
Allan
This problem has been solved, as per Allan's email. Please close.