WordPress.org

Ready to get started?Download WordPress

Forums

WP-Table Reloaded
Hiding & sorting columns (8 posts)

  1. kgagne
    Member
    Posted 2 years ago #

    I used WP-Table Reloaded to create a table of eight columns. Sometimes, I want to display only five columns; on another page, I want to display all eight. I use the hide_columns parameter in the shortcode to accomplish this.

    But I also use aoColumns in the "Custom Commands" of the table definition, which seems to expect me to define a number of columns equal to those being shown in order for tablesorting to work. So sorting will work on one page and not the other with this definition:

    "aoColumns": [ { "sType": "html" }, null, { "sType": "date" }, null, { "sType": "html" } ]

    And vice versa with this:

    "aoColumns": [ { "sType": "html" }, null, { "sType": "date" }, null, { "sType": "html" }, null, null, null ]

    How do I get around this and make tablesorting work regardless of how many columns are being displayed?

    http://wordpress.org/extend/plugins/wp-table-reloaded/

  2. TobiasBg
    Member
    Plugin Author

    Posted 2 years ago #

    Hi,

    yes, that explanation is correct. The solution is to switch to a (relatively) new and better parameter for this: aoColumnsDef instead of aoColumns (http://datatables.net/usage/columns). That new parameter is independent of the actual number of columns, and should work on both pages:

    "aoColumnDefs": [ { "sType": "html", "aTargets": [ 0, 4 ] }, { "sType": "date", "aTargets": [ 2 ] } ]

    Regards,
    Tobias

  3. kgagne
    Member
    Posted 2 years ago #

    Thank you, Tobias!

    When using either aoColumns or aoColumnsDef in combination with hide_columns, I sometimes get this error when loading the page with the embedded table:

    DataTables warning (table id = 'wp-table-reloaded-id-2-no-1'): Requested unknown parameter '5' from the data source for row 0

    Do you know what might cause that?

    If I remove the hide_columns parameter, the error goes away.

    –Ken

  4. TobiasBg
    Member
    Plugin Author

    Posted 2 years ago #

    Hi Ken,

    on which page does this happen?

    Regards,
    Tobias

  5. kgagne
    Member
    Posted 2 years ago #

    Tobias,

    My table has 8 columns with these custom commands:

    "aoColumnDefs": [ { "sType": "html", "aTargets": [ 1, 6 ] }, { "sType": "date", "aTargets": [ 4 ] } ], "bAutoWidth": false

    I display 7 columns without issue here:

    http://www.open-apple.net/ebay/

    using this shortcode:

    [table id=2 print_description=false first_row_th=true hide_columns="8" column_widths="8%|15%|10%|14%|12%|8%|33%%" use_tablesorter=true /]

    For the purpose of testing, I've created this page that calls five columns:

    http://www.open-apple.net/testing-wp-table-reloaded/

    using this shortcode:

    [table id=2 print_description=false first_row_th=true filter="Show14" hide_columns="1,3,8" column_widths="15%|14%|16%|12%|43%" use_tablesorter=true /]

    (I sometimes use shortcode parameters that are redundant with options I've set elsewhere... LMK if that's an issue.)

    -Ken

  6. TobiasBg
    Member
    Plugin Author

    Posted 2 years ago #

    Hi,

    thanks for the examples.

    The problem is that "6" in the "Custom Commands". That "6" targets the 7th column of the shown table. However, when hiding some columns (i.e. 1, 3, 8), there are only 5 columns visible. Due to that the JavaScript code fails.
    So, as it seems the idea with the new aoColumnDefs doesn't work with this specific structure of your table. It would work with the example code that you posted above, but not with this table :-(

    (And: Those Shortcode parameters are no problem.)

    Regards,
    Tobias

  7. kgagne
    Member
    Posted 2 years ago #

    Thanks, Tobias. It sounds like if I rearrange the columns so all the ones with special types are within the first six, it should work. I'll give it a try.

  8. TobiasBg
    Member
    Plugin Author

    Posted 2 years ago #

    Hi,

    Yes, exactly. As long as the column numbers in the "Custom Commands" (zero-based counting) don't exceed the number of columns (in the small table), it should work.

    Regards,
    Tobias

Topic Closed

This topic has been closed to new replies.

About this Plugin

About this Topic