community-forum icon indicating copy to clipboard operation
community-forum copied to clipboard

[Feature Request] Show/hide columns via AJAX

Open joelmellon opened this issue 3 years ago • 2 comments
trafficstars

The ability to dynamically determine which columns are visible on the server-side for AJAX requests would be really valuable.

For CRUD lists that have many columns, obviously there's not always enough screen real estate to accommodate them all. Of course there's the priority option on columns but that only works on the first page load, not when changing filters, searching, paging, etc.

I can think of tons of use cases for this functionality, but they generally involve hiding or showing columns based on selected filters.

If I filter by User Type for example, I'd expect to have that column visible most likely. I could also see a use case for hiding it as well, since we'd know what's being filtered. Regardless, it would be nice to have control over that logic server-side in the setupListOperation() method.

Another example would be to show the column(s) that a search matched. So if I search for "Rob" I'd expect to see the First Name column if a user's name was Robert, and/or the Last Name column if the user's name was Roberts.

A nice-to-have would be some sort of automatic capability to do this based on the passed in filters, but at the core, the ability to somehow include the priority column attribute in the AJAX request, then have the data table know what to do with that is the critical part.

joelmellon avatar Mar 22 '22 21:03 joelmellon

Excelente idea! I vouche for this too! Not sure about the difficulty to implement it in datatables side.

pxpm avatar Mar 23 '22 12:03 pxpm

Yeah, the biggest issue is that DataTables indexes the columns numerically instead of naming them, so hiding and showing columns dynamically client-side isn't easily done. I've run into this in DataTables in the past, and it sucks. Looking through the JS and HTML in this example demonstrates that limited functionality.

So, in an AJAX request, we'd have to determine the numeric index of the first_name column, for example server-side, probably by looping through $this->crud->columns() or something. And due to Backpack's utilization of the priority field, this gets even more complicated. (It's a good thing, just complex.)

I may dig into it some day, but I'm not sure this would be trivial. Ideally, this would be a DataTables enhancement, but they're huge and probably aren't as flexible as the wonderful developers here. 😉

joelmellon avatar Mar 23 '22 16:03 joelmellon