Get 2024 Templates Mega Bundle!14 Bootstrap, Vue & React Templates + 3 Vector Sets
Get for 99$

Toggling column visibility removes table header title


Hi,

I am using KTDatatables Metronic v7 and want to toggle column visibility.


datatable.column(parseInt(val)).visible(false);
where val is the column index.

This works perfectly in terms of removing the column from view and setting the parameter to true again to bring it back. However on bringing it back the table header column title is not restored. I need to execute an extra

datatable.reload();
to get back my table header for the column I previously removed from view.

How can I remove a column from view and bring it back including the table header?


Text formatting options
Submit
Here's a how to add some HTML formatting to your comment:
  • <pre></pre> for JS codes block
  • <pre lang="html"></pre> for HTML code block
  • <pre lang="scss"></pre> for SCSS code block
  • <pre lang="php"></pre> for PHP code block
  • <code></code> for single line of code
  • <strong></strong> to make things bold
  • <em></em> to emphasize
  • <ul><li></li></ul>  to make list
  • <ol><li></li></ol>  to make ordered list
  • <h3></h3> to make headings
  • <a></a> for links
  • <img> to paste in an image
  • <blockquote></blockquote> to quote somebody
  • happy  :)
  • shocked  :|
  • sad  :(

Replies (6)


Hi,

Could you please try to use this function?


datatable.redraw();


Thanks



I tried. Does not work unfortunately.


datatable.column(parseInt(val)).visible(true);
datatable.redraw();



Hi Tristan,

Sorry for the inconvenience. Please note that we have stopped providing updates for KTDatatables since Metronic v8. For future data table updates, we use the Datatables.net plugin.

In our online demo, showing and hiding a column is working.
https://preview.keenthemes.com/metronic/demo1/crud/ktdatatable/api/methods.html

In file;
\theme\demo1\src\js\pages\features\ktdatatable\api\methods.js

Please try to use datatable.columns instead of datatable.column function.


datatable.columns(parseInt(val)).visible(false);



Thanks



Hi!

I tried to use columns instead of column, but this give error:

TypeError: undefined is not an object (evaluating 'delete options.columns[index].visible')



I checked the example of again
\theme\demo1\src\js\pages\features\ktdatatable\api\methods.js

and applied it to my code. It works now. Thanks!



Hi Tristan,

Sorry for the delay. Glad you found it. Feel free to let us know if you need any help.

Thanks


Text formatting options
Submit
Here's a how to add some HTML formatting to your comment:
  • <pre></pre> for JS codes block
  • <pre lang="html"></pre> for HTML code block
  • <pre lang="scss"></pre> for SCSS code block
  • <pre lang="php"></pre> for PHP code block
  • <code></code> for single line of code
  • <strong></strong> to make things bold
  • <em></em> to emphasize
  • <ul><li></li></ul>  to make list
  • <ol><li></li></ol>  to make ordered list
  • <h3></h3> to make headings
  • <a></a> for links
  • <img> to paste in an image
  • <blockquote></blockquote> to quote somebody
  • happy  :)
  • shocked  :|
  • sad  :(
Text formatting options
Submit
Here's a how to add some HTML formatting to your comment:
  • <pre></pre> for JS codes block
  • <pre lang="html"></pre> for HTML code block
  • <pre lang="scss"></pre> for SCSS code block
  • <pre lang="php"></pre> for PHP code block
  • <code></code> for single line of code
  • <strong></strong> to make things bold
  • <em></em> to emphasize
  • <ul><li></li></ul>  to make list
  • <ol><li></li></ol>  to make ordered list
  • <h3></h3> to make headings
  • <a></a> for links
  • <img> to paste in an image
  • <blockquote></blockquote> to quote somebody
  • happy  :)
  • shocked  :|
  • sad  :(