Okay
  Public Ticket #1017063
Conditional formatting in non-visible column
Closed

Comments

  •  2
    Michael started the conversation

    Dear Support-Team,

    I have recognized that conditional formatting, for example setting the color of a row, does not work when the column is set to invisible.

    I tried to set row colors based on IDs in the wdt_ID-column. Since no one needs to see this column, I set it to invisible. Unfortunately, no formatting is applied for this row then.

    Is that a bug or a feature? Is there a way to change that?

    Cheers Michael

  • [deleted] replied

    Hi Michael,
    Thank you for your purchase.

    It is a feature. We will consider to change that in one of the future releases. 

    As a workaround I will explain you what you have to do to accomplish it. First you have to set conditional formatting for that column that you want to be invisible. You will have to define two rules:

     1. If cell value = Online Set row color Green 2. If cell value = Offline Set row color Red

    For that column DO NOT uncheck visible checkbox because conditional formatting will not be applied in the table.

    After defining rules, to hide that column and to have conditional formatting in same time you will have to add this little script on your page where the table is located.

    <script>
    jQuery( window ).load(function() {
        wpDataTables.table_1.api().columns(0).visible(false)
    });
    </script>
    

    Where number 0 is the first column in the table, 1 is second, 2 is third...  Just change it with the number of the column you want to hide.

  •  2
    Michael replied

    Hi Milos,

    Thank you for your fast reply. Your support is great!

    I expected that it was going to result in a little javascript workaround at runtime. ;-) Unfortunately, when using the script, my console throws a TypeError: "wpDataTables.table_8 is undefined". I used table_8 since it is the id of the table on the respective page. table_1 shows the same error as well btw. ;-)

  • [deleted] replied

    Hi Michael,

    You are welcome. Thank you for your kind words. It is not the ID of the table from shortcode. You can find that id when you inspect table element with developer tools in any browser.

  •  2
    Michael replied

    Hi Milos,

    you are absolutely right. I just found the right object. For some reason , the formatting vanished anyway now. I have defined four rules for the column at the moment. I am adding a custom css class. (see picture)

    When I inspect the respective rows, I see that the css-class is no longer applied after using the script.

    Do you have an idea why this happens? I know that it should not...

  • [deleted] replied

    Hi Michael,

    Sorry I didn't understand you clearly. Did you successfully hide columns with little JavaScript? Do you say when you hide them there will no longer be classes that you defined in conditional formatting for that row?

  •   Michael replied privately
  • [deleted] replied

    Hi Michael,

    This is not the best solution but can you try does it work like this:

    
        jQuery( window ).load(function() {
           setTimeout(function() {
               wpDataTables.table_1.api().columns(3).visible(false);
           },"1");       
        });    
    
    
  •   Michael replied privately
  • [deleted] replied

    Hi Michael,

    This workaround worked with previous version. I tried now on current one and seems that it doesn't work. Please provide me a temporary WP-admin login for your site where this happens, so we could log in and take a look ‘from the inside’ as that’s the most efficient way to see and resolve the issue. You can write credentials here just check private and nobody can see it except us.