How do I change the visibility of column dynamically?

How do I change the visibility of column dynamically?

felipesmendesfelipesmendes Posts: 5Questions: 2Answers: 0

Folks,

I'm using meteor-tabular package who uses DataTables behind, so I need to change the visibility dymanic according by user configuration.

Something like this:

...
columns: [{
data: "name",
title: "Name",
className: "center aligned",
orderable: true,
visible:function(){
//If user set to see this columns returns true else return false
}
}, {
data: "ultimaPosicao.id",
title: "ID",
className: "center aligned",
orderable: false,
visible:function(){
//If user set to see this columns returns true else return false
}
}];
...

Have some way or another way to do?

Thank you so much for atention!

Answers

  • allanallan Posts: 63,799Questions: 1Answers: 10,514 Site admin

    I don't quite understand why you can't use columns.visible? It takes a boolean value, not a function.

    Allan

  • felipesmendesfelipesmendes Posts: 5Questions: 2Answers: 0

    @allan

    Because I need to do a query in my database and verify that the user configured to display this column.

  • allanallan Posts: 63,799Questions: 1Answers: 10,514 Site admin

    Can't you just run that function before you initialise the DataTable though? Also, its worth noting that even if the column is hidden, the data is still present on the client-side. So all your user would have to do is run $('#tableId').DataTable().columns().visible(true); to see the data they shouldn't have access to!

    It would be more secure to simply not include the information that they shouldn't have access to.

    Allan

This discussion has been closed.