Okay
  Public Ticket #3242026
Hide colums in frontend
Closed

Comments

  • Pablo started the conversation

    Is creating a filter for hide/show columns at the frontend possible? Something like a column selector for readers.

    Or even an option that hides the column if no data is on any cell of a column?

    Thank you in advance.

    Pablo


  •  1,849
    Miloš replied

    Hi, Pablo.

    Thanks for reaching out to us.

    -

    1. To hide/show columns on the front-end, with the current plugin's built-in capabilities,

    we only have this option with Table Tools, if you enable it in back-end table settings/Table Tools/Column visibility;

    1567372438.png

    then users on front-end will be able to go in this button, and they can toggle visibility on the available columns.

    9970511102.png

    You can check more about our Table Tools here https://wpdatatables.com/documentation/table-features/table-tools/.


    2. Regarding an option that hides the column depending if cells are empty;

    We only have Conditional Formatting at the moment;

    but this is not able to check if all the cells of a column are empty > and only in that case to hide the column;

    you can only set a rule, if any of the cells is empty - then hide the column.

    For example, if i do this on my table here, and set this Condition on Column 'Name",

    6484931126.png
    3532278937.png

    then if i edit any cell in this column, set it as empty - the entire column will hide.

    5151682117.png

    That is what we currently have available as built-in solutions.

    If you have an idea how we might improve this, or to add new options you need,

    Please feel free to search on our suggestions page

     to see if someone may be already suggested this feature. If you can't see it, feel free to add your suggestion there,  and as more people vote, the feature will move higher on the priority list.

    You can certainly follow our changeLog page if you'd like ( it is also available in the plugin dashboard), where we state any changes/new features/bug fixes during updates;

    and our newsletter, so you're informed about new features, bug fixes, freebies, etc.

    -

    If you have coding skills and wish to try to make a custom solution now,

    you can check out our available hooks for Developers on this documentation and see if you can find any hook that might help.

    Please be advised that custom solutions with hooks are not included in our support.

    You can also research resources such as Stack Overflow to see if any other user perhaps found a workaround.

    ( We do like to give examples for certain solutions, but for this use-case, we, unfortunately, don't have anything yet)

    Kind Regards, 

    Miloš Jovanović
    [email protected]

    Rate my support

    Try our FREE mapping plugin! MapSVG - easy Google maps, interactive SVG maps and floor plans, choropleth maps and much more - https://wordpress.org/plugins/mapsvg-lite-interactive-vector-maps/

    wpDataTables: FAQ | Facebook | Twitter | InstagramFront-end and back-end demo | Docs

    Amelia: FAQ | Facebook | Twitter | InstagramAmelia demo sites | Docs | Discord Community

    You can try wpDataTables add-ons before purchasing on these sandbox sites:

    Powerful Filters | Gravity Forms Integration for wpDataTables | Formidable Forms Integration for wpDataTables | Master-Detail Tables

  • Pablo replied

    Great! Milos. You are a great TEAM! Thank you for your fast and helpful answer. 

    Just a question more ;-) related to the solutions exposed:

    When you hide a column, how do the charts related to the table also hide the data source of the data/column?

    Thank you.

    Pablo


  •  1
    Scott Bowie replied

    Hey guys, I have the exact same requirement for hiding a column if all values are empty and quite happy to come across this post as it gave me the starting point to solve it (although I'm not sure it would be efficient for a large table).

    Pablo, can you assign a column class of hideColumn as a default for all columns that you *may* want to hide? Then you could use the conditional formatting as Milos suggested to test for cell <> NULL and assign the column class showColumn as defined below:

    .columnHide {
        display: none;
    }
    .columnShow {
        display: revert !important;
    }

    This has worked for my small table - hope it works for you!

    Cheers, Scott

  •  1,849
    Miloš replied

    Hi, Scott.

    Thank you very much for sharing this workaround idea, 

    we made a note of it for other users who might have the same use-case,

    or wish to try the same solution, it should certainly work regardless of the size of the table's data-set.smile.png

    I tried it on a smaller and a bit larger table, they both worked, so it is safe to assume it should work on all table sizes.

    We can also make multiple Conditional rules - each next rule overrides the last one/ or in other words, has higher priority than the next one, so there might be other possibilities, as well,

    i guess it depends on the specific use-case and user's preference.

    -

    2. In regards to having the chart "react" to conditional formatting or hiding/showing column in source table,

    unfortunately, charts do not have this capability.

    It is not possible for a chart to pass any Conditional Formatting,  or number format, or suffix/prefix from source tables.

    To change the charts like that, you would have to add custom chart callbacks.

    Every chart engine has its own layout and its settings.

    We use free libraries for chart engines, and they are limited as to what we can change from within the plugin's UI.

    You can check out all the available chart engines and examples of wpDataCharts documentation here . 

    If the options you need are not in the chart creation wizard,  you can try to find a custom solution using chart callbacks.

    You can check our documentation about wpDataCharts callbacks

    • Every chart exposes several options that customize its look and feel. Charts usually support custom options appropriate to that visualization. wpDataChart callbacks allow adding options that are available in Google Charts APIHighcharts API, and Chart.js API
    • All necessary resources are available in charts engines API (depends on which one you use). Every engine has a different approach to chart settings. In wpDataChart callbacks, you have to adopt those settings to the wpDataChart object (you can take a look at examples for each engine in our documentation, and also in the Support help center). A huge number of examples for any area of programming can be found on stackoverflow.com (typing your problem in google and at the end add "site: stackoverflow.com" and Google will search only that website). Also, a lot of examples of charts, chart settings, and customization can be found on jsffidle.net (typing in google for example "line chart highcharts jsffidle")
    • Please note that using hooks or wpDataTable and wpDataChart callbacks requires a certain level of programming skills and included support refers only to advice.

    -

    For example, for a use-case where you would like to have charts "ignore" or "skip" NULL and zero values,

    let's say if we had a line chart like this, and i set a numeric column to have all NULL ( for numerics they convert to zero);

    then on a line chart this column will show  a "flat line" for that series ( note the green series)

    1914563993.png

    If you need your charts to skip/ignore NULL/zero values,


    Please go to the functions.php file of your theme or child theme, and add this:

    function filterNullValues ($value, $origHeader ,$chartID, $tableID){
         // You can add conditions for specific org header, chart id or table id
        // Here we only check if value is null and provide same value to the chart object
        if (is_null($value) || $value == 0){
            $value = null;
        }
        return $value;
    }
    add_filter( 'wpdatatables_filter_int_cell_data_in_charts', 'filterNullValues', 10, 4 );
    add_filter( 'wpdatatables_filter_float_cell_data_in_charts', 'filterNullValues', 10, 4 );

    This works for integer and float columns that have NULL values and "0" values.

    If you want to apply it just for NULL values, you can use this code:

    function filterNullValues ($value, $origHeader ,$chartID, $tableID){
         // You can add conditions for specific org header, chart id or table id
        // Here we only check if value is null and provide same value to the chart object
        if (is_null($value)){
            $value = null;
        }
        return $value;
    }
    add_filter( 'wpdatatables_filter_int_cell_data_in_charts', 'filterNullValues', 10, 4 );
    add_filter( 'wpdatatables_filter_float_cell_data_in_charts', 'filterNullValues', 10, 4 );
    

    And if you want to apply it just for "0" values, you can use this code:

    function filterNullValues ($value, $origHeader ,$chartID, $tableID){
         // You can add conditions for specific org header, chart id or table id
        // Here we only check if value is null and provide same value to the chart object
        if ($value == 0){
            $value = null;
        }
        return $value;
    }
    add_filter( 'wpdatatables_filter_int_cell_data_in_charts', 'filterNullValues', 10, 4 );
    add_filter( 'wpdatatables_filter_float_cell_data_in_charts', 'filterNullValues', 10, 4 );
    

    You don't need to change the code after the plugin updates, but you will need to keep this code in functions.php.

    If you want to connect data with NULLs skipped, you can use this callback: https://jsfiddle.net/gh/get/library/pure/highcharts/highcharts/tree/master/samples/highcharts/plotoptions/series-connectnulls-true/

    <script type="text/javascript">
    jQuery(window).on('load',function(){
        if( typeof wpDataChartsCallbacks == 'undefined' ){ wpDataChartsCallbacks = {}; }
        wpDataChartsCallbacks[16] = function(obj){
            obj.options.plotOptions = {
                series: {
                    connectNulls: true
                }
            }
        };
    });
    </script>
    

    Just make sure to replace [16] with the ID of your chart.

    -

    I hope this helps.smile.png

    Kind Regards, 

    Miloš Jovanović
    [email protected]

    Rate my support

    Try our FREE mapping plugin! MapSVG - easy Google maps, interactive SVG maps and floor plans, choropleth maps and much more - https://wordpress.org/plugins/mapsvg-lite-interactive-vector-maps/

    wpDataTables: FAQ | Facebook | Twitter | InstagramFront-end and back-end demo | Docs

    Amelia: FAQ | Facebook | Twitter | InstagramAmelia demo sites | Docs | Discord Community

    You can try wpDataTables add-ons before purchasing on these sandbox sites:

    Powerful Filters | Gravity Forms Integration for wpDataTables | Formidable Forms Integration for wpDataTables | Master-Detail Tables

  • Pablo replied

    Thank you very much to all. We will try to implement this solution. 

    Pablo

  •  1,849
    Miloš replied

    Hi, Pablo.

    Apology for the waiting time - we don't work on weekends, so it adds 2 more days.

    No problem, i am happy to advise as much as possible/ as much as our support can cover.smile.png

    Let us know if you have any additional questions on what we covered on this ticket;

    or if you have new questions, please open a new ticket.

    Thank you.

    Kind Regards, 

    Miloš Jovanović
    [email protected]

    Rate my support

    Try our FREE mapping plugin! MapSVG - easy Google maps, interactive SVG maps and floor plans, choropleth maps and much more - https://wordpress.org/plugins/mapsvg-lite-interactive-vector-maps/

    wpDataTables: FAQ | Facebook | Twitter | InstagramFront-end and back-end demo | Docs

    Amelia: FAQ | Facebook | Twitter | InstagramAmelia demo sites | Docs | Discord Community

    You can try wpDataTables add-ons before purchasing on these sandbox sites:

    Powerful Filters | Gravity Forms Integration for wpDataTables | Formidable Forms Integration for wpDataTables | Master-Detail Tables