datatable waits more than 15 seconds to load

datatable waits more than 15 seconds to load

secoseco Posts: 17Questions: 6Answers: 0

im using datatable like this

$('#provincedataTable').DataTable({
paging:true,
info:true,
ordering:true,
autoWidth:true,
Processing: true,
ServerSide: true,
ajax: 'province/provinces-json',
columns: [
{data: 'select'},
{data: 'code'},
{data: 'name'},
{data: 'options'}
],
"fnDrawCallback": function() {
Checkboxs();
}
});

and the datatable waits more than 15 seconds till it load all the data first then show the first 10 records !!

i want it to load the first page only and when i click the page number it should load from the server
i think this is the right behaviour

how i can do that?

thanks in advance.

This question has an accepted answers - jump to answer

Answers

  • JCR1951JCR1951 Posts: 34Questions: 6Answers: 0
    edited May 2016

    At serverside in php and mysqli you can limit the recordlength .

           SELECT column_name(s)
           FROM table_name
           LIMIT number;
    
  • secoseco Posts: 17Questions: 6Answers: 0

    no i do not to load a limited number
    i want all 4000 record to load buty paginated
    so only the page which contains 10 records only loads

    and when i click on any page it loads those 10 records on it

    the behaviour now is when the page loaded it waits so long till it loads all 4000 records then the table appears

  • allanallan Posts: 61,934Questions: 1Answers: 10,155 Site admin
    edited May 2016

    ServerSide: true,

    There is no ServerSide option - it is serverSide (note the case - Javascript is case sensitive).

    edit Also, does your ajax: 'province/provinces-json', script implement server-side processing?

    Allan

  • secoseco Posts: 17Questions: 6Answers: 0

    now it is like this and still the same behaviour !!

        $('#provincedataTable').DataTable({
            paging:true,
            processing: true,
            serverSide: true,
            ajax: 'province/provinces-json',
            columns: [
                {data: 'select', name: 'select'},
                {data: 'code', name: 'code'},
                {data: 'name', name: 'name'},
                {data: 'options', name: 'options'}
            ],
            "fnDrawCallback": function() {
              Checkboxs();
            }
        });
    

    and im using for server isde script package called
    "yajra/laravel-datatables-oracle": "6.0.x-dev"

  • allanallan Posts: 61,934Questions: 1Answers: 10,155 Site admin

    I haven't used that package, so I can't really comment on it. Is it correctly responding with the information required in the link I gave?

    Allan

  • secoseco Posts: 17Questions: 6Answers: 0

    the data is returned and it is ok but the problem is

    it loads all the data first before show the table showing Loading... indicator
    and that take more than 20 seconds for those 4000 records

  • secoseco Posts: 17Questions: 6Answers: 0

    now i use this code

    $('#provincedataTable').DataTable({
        processing: true,
        serverSide: true,
        ajax: 'province/provinces-json',
        "fnDrawCallback": function() {
            Checkboxs();
        }
    });
    

    this famous error appear
    datatables requested unknown parameter 0 for row 0

    but the data on the console i see only 10 records came ..
    so now the return is correct but it does not appear on the page due to this above error

    the problem in using columns: [] when i remove it this new error came

    what i can do for this new error?
    thanks in advance.

  • allanallan Posts: 61,934Questions: 1Answers: 10,155 Site admin

    We'd really need a link to the page in question. I can really only guess at the moment.

    If all 4000 rows are being loaded that the server-side script is not correctly performing server-side processing.

    Allan

  • secoseco Posts: 17Questions: 6Answers: 0

    this code works but show error

    $('#provincedataTable').DataTable({
    processing: true,
    serverSide: true,
    ajax: 'province/provinces-json',
    "fnDrawCallback": function() {
    Checkboxs();
    }
    });

    the error datatables requested unknown parameter 0 for row 0

    i see the data only in the console of the browser shows 10 records
    means every thing goes good but this error stops it from appear on the page

  • allanallan Posts: 61,934Questions: 1Answers: 10,155 Site admin

    What is the JSON that 'province/provinces-json' returns?

  • secoseco Posts: 17Questions: 6Answers: 0
    edited May 2016

    normal json generated by this package
    http://datatables.yajrabox.com/

    and this is sample lines
    {
    "draw": 0,
    "recordsTotal": 4099,
    "recordsFiltered": 4099,
    "data": [
    {
    "id": 2971,
    "country_id": 195,
    "name": "Álava",
    "code": "AL",
    "status": 1
    },
    {
    "id": 2976,
    "country_id": 195,
    "name": "Ávila",
    "code": "AV",
    "status": 1
    }

  • allanallan Posts: 61,934Questions: 1Answers: 10,155 Site admin

    "draw": 0,

    That is not valid for server-side processing. It must be at least 1. Therefore there is something going wrong. Is it expecting POST data perhaps?

    Allan

  • secoseco Posts: 17Questions: 6Answers: 0

    im sorrry one final thing
    im following this tutorial and the draw is 0 and it is working

    http://datatables.yajrabox.com/fluent/basic

  • allanallan Posts: 61,934Questions: 1Answers: 10,155 Site admin

    It looks correct to me:

    {"draw":3,"recordsTotal":675,"recordsFiltered":675 ...

    Allan

  • secoseco Posts: 17Questions: 6Answers: 0

    no it is 0
    look on this json file used
    http://datatables.yajrabox.com/fluent/basic-data

  • allanallan Posts: 61,934Questions: 1Answers: 10,155 Site admin
    Answer ✓

    I promise you, if you open your browser's network tools and then click to change a page in the DataTable, then take a look at the JSON response from the server. You'll see that it is changing the draw parameter in the returned data.

    Allan

This discussion has been closed.