Problem with custom values for FixedColumns with button initialisation
Problem with custom values for FixedColumns with button initialisation

Link to test case: https://live.datatables.net/popuziga/1/edit/
Description of problem:
If the FixedColumns are initialised via a button, the user-defined number of columns is apparently not taken into account at the beginning. Instead, only the default values (start: 1, end: 0) are used. The custom values only become effective after clicking the button twice (fixation off & on).
For the test case, I copied the JavaScript code from the example and only changed the number of start columns. The problem also occurs with altered end columns.
Have I done something wrong or is it possibly a bug?
Many thanks for your help!
Answers
Hmm - a good question. What is happening is that the button being triggered the first time is disabling FixedColumns (it is already enabled with a single column fixed). Per the
fixedColumns
docs it toggles FixedColumns being enabled and not.Then when you press the button again (i.e. the second time) it will now enable FixedColumns and freeze two at the start.
If you initialised FixedColumns with two frozen columns, or have the button freeze just one column, then the toggling action makes more sense. But switching from 1, to 0, then to 2 (then 0,2,0,2,0...) is confusing.
If you do actually want to go from 1 to 2 frozen column, then perhaps what I need is not a toggle button but a "just do it" button - i.e. click it and 2 columns will be frozen. Is that more inline with what you want?
Allan
Hey Allan,
Thanks for the quick reply. It is indeed confusing, but for me especially that it doesn't start with two fixed columns: How to set up the button initialisation to use the custom configuration from the very beginning?
So my desired behaviour would be 2,0,2,0,2,0...
It's confusing to me too. It seems that on initialization the
config
option supplied is not used during FixedColumns initialization. I My assumption is it would be used. As a workaround I tried using the config option like this:This doesn't work either as shown here:
https://live.datatables.net/popuziga/4/edit
The workaround of using
fixedColumns().start()
in theready()
function does seem to work:https://live.datatables.net/nahotike/1/edit
@allan can comment if he thinks the button
config
settings should be used during FixedColumns initialization.Kevin
is what I would expect to toggle between 2 and 0 fixed columns. That doesn't appear to be happening though, which I'm surprised by. I'll post back shortly when I've looked into that.
Allan
Realised what was going wrong - I hadn't been passing the
config
parameter with the FixedColumns settings into the initialisation (naming error - one day I'll write the whole lot in Typescript to stop this sort of thing...). Commit here.I've updated Kevin's example to show it working now.
Allan