Please submit a private ticket if you need to share sensitive information, such as license details and admin credentials.

Okay
  Public Ticket #3757496
How to use lengthMenu - Any docs?
Open

Comments

  •  2
    Trent started the conversation

    Hi.

    I was trying to edit what options I have in the lengthMenu (items per page).

    I found the link to this: https://datatables.net/reference/option/language

    And worked out how to add more by pasting this in the lengthMenu field under the Localization tab.

    'Display <select>' +
        '<option value="10">10</option>' +
        '<option value="20">20</option>' +
        '<option value="50">50</option>' +
        '<option value="100">100</option>' +
        '<option value="150">150</option>' +
        '<option value="200">200</option>' +
        '<option value="-1">All</option>' +
        '</select> records'
    

    But found that I had to start with an option of 10, otherwise the first option would not be pre-selected.

    Ideally i would like to have:

    'Display <select>' +
        '<option value="20">20</option>' +
        '<option value="50">50</option>' +
        '<option value="100">100</option>' +
        '<option value="150">150</option>' +
        '<option value="200">200</option>' +
        '<option value="-1">All</option>' +
        '</select> records'

    I am interested in perhaps a better explanation as to how to use the lengthMenu if i am not using correctly.

    And then perhaps an answer to why when 20 is the first option the select field is blank with no option pre selected.

    Attached files:  Screen Shot 2024-11-05 at 7.35.12 pm.png

  •  1,200
    Dustin replied

    Hi Trent,

    Please also add the custom code below. (How to add custom code? ↗):

    add_filter( 'wpcvt_datatable_params_arr', function () {
    	return [ 'pageLength' => 20 ];
    } );

    Then, the '20' option will be selected by default.

    Best regards,
    Dustin

  •  2
    Trent replied

    Your solution worked.

    Perfect Dustin, thank you..!