visibility bug

visibility bug

baspromontebaspromonte Posts: 7Questions: 3Answers: 0

This used to work??
I have a session variable defined to hide/show columns that is set on a separate settings page.
Changing the column show/hide value and going back to the table and it is still showing or hiding depending on what it was previously.
Checked the code in the debugger and it is telling it to show when hidden and vice versa.

Example: I just changed the view_all_rooms column to show and yet it is not visible when I come back to the table.

Here is what the debugger is showing.

            { data: 'view_all_rooms', 'visible': 1 },       // 10 View All Rooms Column

Yet if I log out of the web app and back in, it is correct.

I just deleted the session storage key/value for this table: DataTables_staffTable_/team-page.php and refreshed the page, and it worked. I love you session cache values, but when the code says to show or hide a column, that should override what is in the cache. Right? Workaround?

thanks bill a

This question has an accepted answers - jump to answer

Answers

  • kthorngrenkthorngren Posts: 22,159Questions: 26Answers: 5,100

    Changing the column show/hide value and going back to the table and it is still showing or hiding depending on what it was previously.

    I don't follow how you are using the session variable and updating the Datatable column visibility.

    Are you using stateSave?

    Can you post your code to show how you are doing this or better a link to a test case replicating the issue?
    https://datatables.net/manual/tech-notes/10#How-to-provide-a-test-case

    Kevin

  • baspromontebaspromonte Posts: 7Questions: 3Answers: 0

    i have "stateSave": true,
    the first time i load the page i have
    { data: 'view_all_rooms', 'visible': 1 }, and the column shows

    next time i load the page i have
    { data: 'view_all_rooms', 'visible': 0}, yet the column still shows even though i have set visible to 0.

    it appears to be using a DT session value for column visible and overriding what i have changed it to in the code.

    if i turn off stateSave it works yet none of the other state variables are saved.

    Is this the way it is suppose to work?

    I can PM you a link to my app and a temp username and password if that helps

  • kthorngrenkthorngren Posts: 22,159Questions: 26Answers: 5,100
    edited July 8 Answer ✓

    The way stateSave works is the Datatable will initialize with the configured options then load and apply the saved state. You can use stateLoadParams to remove the options you don't want restored. For example this will allow the configured visibility of column 1 to be applied no matter what is saved:

      stateLoadParams: function (settings, data) {
        delete data.columns[1].visible;
      }
    

    Try this example:
    https://live.datatables.net/pesocito/1/edit

    In the JS Bin menu use File > Clone to get a copy you can update. Use the Run with JS button or reload the page and you will see both the Position and Office column are hidden from the two column().visible() statements.

    Either comment out or remove both column().visible() statements and rerun or reload the page. You will see the Position column because of stateLoadParams and not see Office because its visibility was restored.

    The browser's console will show the structure of the saved state after stateLoadParams executes.

    Kevin

  • baspromontebaspromonte Posts: 7Questions: 3Answers: 0

    Kevin
    THANK YOU. that worked perfect. here is how i coded it. is there a cleaner way of doing it?

            stateLoadParams: function (settings, data) 
                for (let i = 7; i <= 11; i++) {
                    if (data.columns[i]) {
                        delete data.columns[i].visible;
                    }
                }
            },
    
  • kthorngrenkthorngren Posts: 22,159Questions: 26Answers: 5,100

    Looks good to me. Glad its working.

    Kevin

Sign In or Register to comment.