如何使用默认搜索值运行datatable api?

I was wondering how to load datatable api with default search value. I tried something like this.

$(document).ready(function{
    $('#datatable').DataTable();
    $("input[type=search]").val('john')
});

But since, in order to show the search results the search box needs to be submitted. How do I this ?

Try triggering a keyup event...

$(document).ready(function{
    $("#datatable").DataTable();
    $("input[type='search']").val("john").trigger("keyup");
});



EDIT

I found a way to disable the pagination when a search is active.
Meaning when the search input field isn't empty.

I refined my solution to also hide the unsefull controls, considering a no-pagination dataTable.

See it on CodePen.

searchField.on("input",function(){

    // Grab the seach term (text inputed in the search field)
    searchTerm = $(this).val();
    console.log("searchTerm: "+searchTerm);

    // The paginate links and buttons...
    var paginate = $("#myTable").siblings('.dataTables_paginate');

    // Remove the whole table when search term is empty.
    if(searchTerm==""){
        console.log("searchField: empty");

        // Set pagination to desired length
        // and show controls.
        myTable.page.len( paginationLength ).columns.adjust().draw();
        paginate.show();
        pageLenghtSelect.show();
    }else{
        console.log("searchField: NOT empty");

        // Set pagination to no pagination at all (only one page).
        // and hide controls.
        myTable.page.len( -1 ).columns.adjust().draw();
        paginate.hide();
        pageLenghtSelect.hide();

    }
});