Hide column in listview

Hi, I need to hide some columns in the listview, based on the type of role of the person accessing the system.

to do this I created the file, inside the custom module, view.list.php:

require_once('include/MVC/View/views/view.list.php');

class <MY_MODULE>ViewList extends ViewList {


public function preDisplay() {
       
parent::preDisplay();
global $current_user;

$objACLRole = new ACLRole();
$roles = $objACLRole->getUserRoles($current_user->id);

if($roles[0] == "Customer"){
...
}
}

function display() {
parent::display();
}

}

What I’m missing is a parameter to set to hide the column, to be inserted inside the if:


if($roles[0] == "Customer"){
...
}

something like set column <MY_COLUMN> hide.

Does anyone know how to implement this? Thank you.

Anyone know how to help me? Please

If you’re using a debugger, set a break-point there and examine the existing variables in that scope.

Maybe you can try clearing the field from the viewDefs and it will disappear (temporarily, only in that request being handled, because you’re not changing any files).

I discovered that in viewdefs there is the default parameter… if set to false, the column is deleted, but it is moved to the ‘available’ column, this means that a user can still change the layout and make that column available.

I tried modifying the listviewdefs like this:

'default' => false,
'available' => false,
'hidden' => true,

but the result does not change, the columns disappear from the default layout, but are inserted among the available ones.
I really have no more ideas.

Have you tried deleting the entire entry from the array? That’s what I meant in my suggestion.

yes, i tried this too, if i delete the line

default => true,

it’s like if you set default to false, then it would become invisible but available

I would also like to remove the ability to access the column selector (for certain users), but I don’t know where the object is

<a href="#" class="glyphicon glyphicon-th-list" data-toggle="modal" data-target=".modal-columns-filter" title="Column selection"></a>

and how to disable it

Delete the entire entry, one level above that. Make the field 100% non-existent in the viewdefs

sure, so no one sees it, but I want only some roles not to see it

You have a condition to test the role, right? So remove the field only when you want.

If I understand correctly, you are in the part of the code that is rendering the view, so what you do there is specific to what is being sent to a specific browser, this particular time.

If I understand your suggestion correctly, you say:
in view.list you identify the role, if it’s customer you remove that section, otherwise, if that section doesn’t exist, you add it. Right?

in this case, how can I do it?

That is correct. I can’t give you detailed instructions from here (I’m on my vacation). But you posted code above, you have the if there, use it! I don’t know exactly how you’re referencing the viewdefs, but you would just need to remove that item from the correct array.

Understood, this is what I don’t know how to do, add and delete that section… I hope someone else knows how to do it, thanks and have a nice holiday

It should be something along the lines of

unset viewDefs["somefieldname"];

but you’ll have to pay attention to the array structure there might be more levels to it

ok i try it, and to add it?

You can read up on PHP arrays in many places online

https://www.google.com/search?q=php+assigning+associative+arrays

something like

viewDefs["newEntry"] = array (
   'default' => false,
   'available' => false,
   'hidden' => true,
);

but again, I am not looking at the actual array, I don’t know if these are the correct names or if there are more levels there.