Viewing 7 replies - 1 through 7 (of 7 total)
  • Plugin Author Meitar

    (@meitar)

    I have a spreadsheet with around 20 column headers. By default I only want one selected under the ‘column visibility’ tab to show on load, not all of them.

    https://datatables.net/reference/option/columns.visible

    Thread Starter ouzifeng

    (@ouzifeng)

    Thanks, may be slightly beyond me.

    Where do I paste the necessary JS script

    Plugin Author Meitar

    (@meitar)

    From the FAQ:

    How do I change the default settings, like can I turn paging off? Can I change the page length? Can I change the sort order?

    All of these DataTables options are accessible through shortcode attributes. The shortcode attribute is an underscore-separated version of the DataTables’s CamelCase’ed option name, prefixed with datatables_. For instance, to turn off paging, you need to set the DataTables paging option to false, so you would use a shortcode like this:

    [gdoc key="ABCDEFG" datatables_paging="false"]

    Similarly, to change how many rows appear per page, you need to use the DataTables pageLength option, setting it to a number. Its default is 10, so if you wanted to show 15 rows per page, you would use a shortcode like this:

    [gdoc key="ABCDEFG" datatables_page_length="15"]

    Putting that together with the fact that the DataTables option you’re looking for is columns.visible, you should be able to deduce that there is a shortcode attribute that allows you to set the value of the columns.visible DataTable configuration option for your sheet.

    Sure enough, if you actually read the README file that comes with this plugin (or just click around on this website), you’ll find that there is a complete listing of all the shortcode attributes this plugin provides. That list is on this page.

    The next step is to examine that list of recognized attributes and see if one matches the pattern of being an underscore-separated name for the option you want. Here is an excerpt of that list from that page:

    • datatables_search
    • datatables_state_duration
    • datatables_stripe_classes
    • datatables_select
    • datatables_tab_index
    • datatables_column_defs
    • datatables_columns

    Since you want to customize the columns.visible option, it’s unlikely that the datatables_tab_index attribute is the one you want, right? I believe you can figure out which attribute you need to use. ??

    Hi,

    I’m fighting with the same thing. I would actually want to show 4 columns on the load. But for now it would be nice just to be able to hide some columns.

    Tried this: [gdoc key="1If0o0M_3DKMBNmWB4Yb4VX8Tw-KWOjezH9FNh7hxEx4" use_cache="no" datatables_column_defs='%5B{ "targets":2 }%5D']

    No luck. I’m starting to get frustrated and out of ideas. So I would kindly appreciate a small push to the right direction.

    I’ve added “visible”: false and no success.

    [Moderator Note: No bumping, thank you.]

    At this point I wrote a jQuery script that pushes the buttons accordingly to achieve this. But it is not elegant nor very vise solutions. So I would still kindly appreciate some kind of note how to. I have to say that it seems I am not alone with this, so would it be possible to add this information in the manual?

    Plugin Author Meitar

    (@meitar)

    would it be possible to add this information in the manual?

    This information already is in the README file shipped with this plugin, also visible on this website, and on the DataTables option page linked above. You even have the right idea in your example.

    Translating the second example on the DataTables manual page linked above, to hide the first column of five columns:

    datatables_columns='%5B {"visible": false}, null, null, null, null %5D'
Viewing 7 replies - 1 through 7 (of 7 total)
  • The topic ‘Change number of column shown on load’ is closed to new replies.