apply the column hide functionality for appended data
apply the column hide functionality for appended data

Hi,
Case-1) I have a datatable which include the rowGroup functionality, the table looks like this .
http://live.datatables.net/babifane/1/edit
Case-2) when I hide the column 3 , it doesn't hide the .append data (<td>)
used in rowGroup, as shown in the example below .
live.datatables.net/kemiyaxu/1/edit
If I hide the column 3 , how can I hide the.append(<td>) data
used in rowGroup
Thank you
This question has an accepted answers - jump to answer
This discussion has been closed.
Answers
Your code needs to consider the visibility of the columns when creating that grouping row. You also need to issue a
draw()
when changing the visibility to ensure the grouping row is redrawn.This thread may help, as it's discussing this issue too.
Colin
Hi @collin
Thank you. This code in the thread works fine.
Step-1 : I included column visibility in rowGroup and it works fine
step-2 )
For this case, the redraw function below cause an error
seems to cause an error :
datatables.js:5751 Uncaught RangeError: Maximum call stack size exceeded
step-3) I tried to remove the
drawCallbackfunction
which I used to hide columns and it doesnt show any error.Does it mean I need to call the redraw function somewhere inside drawcallback?
Please help
Thank you
The problem is you are setting column visibility (
this.visible(false);
) withindrawCallback
which is invoking thecolumn-visibility
event which is calling theapi draw()
API causing thedrawCallback
to run. Causing the infinite loop error you are getting.Try this code in
initComplete
to initially hide these columns.Kevin
@kthorngren
Thank you. I got the problem but, in my case I guess I will have to use
drawCallback function
because of following reasons:1) Based on the dropdown selection my table header names change. So on each selected value in dropdown there has to be a new draw function to get new header values.
2) Also, based on individual values in the dropdown list, some columns need to be hidden based on their values. example if column has all zero values it is hidden. I have to check this on each draw.
For example , in the image-1 ,

if I select TOMATOES , table looks like this
and in image-2 if I select APRICOTS , table looks like this

I hope it makes sense. is there any other way around?
Thank you
You could use global flags to determine to run code in the callback - not pretty but they do the trick.
Colin
Hi @colin
Thank you. Can you please give me a very basic example or just an Idea how should I start/proceed with that?
Thank you
Here is one idea (pseudo code):
Another option might be to use turn the event off at the start of
drawCallback
then turn it back on at the end ofdrawCallback
.Kevin
@kthorngren
Thank you. I have been trying a lot but no luck.
1) Every time when the column visibility changes and when the draw is called
callDraw = True;
it goes in loop again.2) as per my understanding when the drawback function is called and if
callDraw is set to false
it shouldn't invoke the function again.2)
tried turning it off using
table.off( 'column-visibility.dt');
and then again turned it on usingtable.on( 'column-visibility.dt');
but didnt workThank you
Best thing to do is to build a simple test case with
drawCallback
and thecolumn-visibility
event to see how to control the behavior. Then if you still need help we can look at the test case to help debug.https://datatables.net/manual/tech-notes/10#How-to-provide-a-test-case
It is possible that my pseudo code isn't fully correct since its not tested
It was meant to give you an idea of what to do.
Same with this. Not sure what you did but if you want to debug it please build a test case showing what you tried.
Kevin
@kthorngren Thank you very much.
I tried to create a test case but it seems to work here with out need to
call for table draw() to recalc the RowGroup.
If you look at the example in the link below live.datatables.net/wevobuzi/1/edit
step-1) In the dropdown menu if you select : ** Ashton Cox ,** it hides the

column 'f'
using the code inside drawCallback function. and calculates the RowGroupstep-2) In the dropdown menu if you select : Angelica Ramos , it hides the

column e and f
, using the code inside drawCallback function and alculate steh rowGroupIn my case when the column e is hidden the , the stats shown are wrong. instead of 57 it will show 0.
Thank you
So you re saying the test case is working as expected but your page is not, correct? To help debug we will need to see the problem occur. There must be something else in your page, that is not in the test case, that is changing the behavior.
Kevin
HI @kthorngren
Thank you. Yes, that is right. It is not showing me any error rather than the rowgroup calculations are shows as 0, after columns are hidden.
Here is my actual code and it is similar to one in example except serverside=true, just in case you can see something wrong here.
However, I think I will have to debug my code step by step. Time consuming
The calculations will be based on the data in the client. With server side processing that is limited to the page being displayed. Guessing that might be the problem.
Kevin
Hi @kthorngren
thank you. I have been trying with different scenarios but didn't work. I created a more realistic test case for this issue.
live.datatables.net/wixohopi/1/edit
If you notice in the example, inside
Column visibility event
I have set callDraw to callDraw = false , the rowgroup calculations are not redrawn after columns are hidden.But as soon as you try to redraw the rowGroup calculations after column visibility changes by making callDraw = true the screen freezes , assuming it goes in a continuous loop.
Thank you
Not sure why you have a settimeout function. I commented that out.
You have
It should be
callDraw
. Fixed that.I removed the
callDraw = false; // Make
you have in thecolumn-visibility
and addedcallDraw = true;
after the loop in the `-option drawCallback. Seems to work now.http://live.datatables.net/fosuxapa/1/edit
Kevin
@kthorngren Thank you very much. You made my day
Regards
KT