3

I have a search bar, by default it's loading all the data under the search bar. I want to limit the default before searching to be only 5 results in the table.

I'm trying this but it doesn't work! What I'm doing wrong?

<script>
$(document).ready(function(){
    load_data();
    function load_data(query)
    {
        $.ajax({
            url:"fetch.php",
            method:"post",
            data:{query:query},
            success:function(data)
            {
                $('#result').html(data);
            }
        });
    }

    $('#search_text').keyup(function(){
        var search = $(this).val();
        if(search != '')
        {
            load_data(search);
            $('#result').dataTable({'iDisplayLength': 5});
        }
        else
        {
            load_data();            
        }
    });
});
</script>

And the HTML part is just this code:

<div id="result"></div>
Harshith Rai
  • 3,018
  • 7
  • 22
  • 35
jason5137715
  • 117
  • 1
  • 8

1 Answers1

0

if you are using datatbles then you have to pass pageLength: 5.

$('#example').dataTable( {
  "pageLength": 5
} );

you can see in this link