This is pretty simple, but I need to be able to toggle showing columns in a table.
The idea is to have a function that will take the name of the column (all the rows have the same data-field in the same column) and hide it, adjusting the width of the table as it goes.
Using Chrome's inspector, I came up with a simple proof of concept
$('[data-id="column"],[data-field="column"]').toggle()
After running the above, I need to adjust the width of the element plus / minus 4 pixels for the table to fit correctly - The table renders a white box on the right hand side where the column(s). This is just a proof of concept and the actual width will be stored in a variable that will be manipulated to allow multiple columns to be hidden.
$(".oe_list_content").width($(window).width()+/-4)
I made a simple function to come up with the initial idea, but when I run the function, it returns undefined and doesn't make the changes. I'm fairly certain that it can, but is the jQuery selector not able to take a function variable?
function rowToggle(row){
// Verify the rows even exist in the DOM
if($('[data-id="'+row+'"]').length){
$('[data-id="'+row+'"]','[data-field="'+row+'"]').toggle();
if($('[data-id="'+row+'"]').is(':hidden')){
$(".table").width($(window).width()+4);
}else{
$(".table").width($(window).width()-4);
}
}
}
This really seems like a variable problem because
var row = "column";
$('[data-id="'+ row +'"]').toggle();
doesn't actually toggle the field. Am I missing something?
var row = "column";I hope you realize that is weird. Also if you want a function to return something you must specify areturnstatement.