why don't jquery datatable get filled with newly updated data after searching?

why don't jquery datatable get filled with newly updated data after searching?

This question has accepted answers - jump to:

Answers

  • kthorngrenkthorngren Posts: 21,173Questions: 26Answers: 4,923

    What is in the JSON response from the server for your search?

    Kevin

  • HunaynHunayn Posts: 7Questions: 2Answers: 0

    {"draw":1,"recordsTotal":10,"recordsFiltered":25,"data":[["Hunain","123"],["Hunain","123"],["ravaid"
    ,"123"],["Waleed","123"],["Jim Carrey","123"],["da","asd"],["hunain","321"],["sd","asd"],["bekhudi","123"
    ],["hk","asd"]]}

  • HunaynHunayn Posts: 7Questions: 2Answers: 0

    @kevin

    {"draw":1,"recordsTotal":10,"recordsFiltered":25,"data":[["Hunain","123"],["Hunain","123"],["ravaid"
    ,"123"],["Waleed","123"],["Jim Carrey","123"],["da","asd"],["hunain","321"],["sd","asd"],["bekhudi","123"
    ],["hk","asd"]]}

  • kthorngrenkthorngren Posts: 21,173Questions: 26Answers: 4,923

    This is in the JSON:

        "recordsTotal": 10,
        "recordsFiltered": 25,
    

    recordsTotal should be the total in the DB not what was returned. This doc describes the parameters returned from the server.

    I'm not sure if it will cause problems to report more recordsFiltered than recordsTotal. Maybe you can provide a debug report after the initial table load and one after performing the search. Or if you can provide a link to the page with the problem someone will take a look.

    Kevin

  • tangerinetangerine Posts: 3,365Questions: 39Answers: 395
     "retrieve": true,
    

    I'm not sure that's what you want, looking at the docs:
    https://datatables.net/reference/option/retrieve.

  • HunaynHunayn Posts: 7Questions: 2Answers: 0

    @kthorngren

    thanks for the reply pal but that didn't work.

    I am posting a Request and response after initial table load and after performing a search

    After initial load:

    Request:

    _
    1503560388132
    columns[0][data]
    0
    columns[0][name]
    columns[0][orderable]
    true
    columns[0][search][regex]
    false
    columns[0][search][value]
    columns[0][searchable]
    true
    columns[1][data]
    1
    columns[1][name]
    columns[1][orderable]
    true
    columns[1][search][regex]
    false
    columns[1][search][value]
    columns[1][searchable]
    true
    draw
    2
    length
    10
    order[0][column]
    0
    order[0][dir]
    asc
    search[regex]
    false
    search[value]
    2
    start
    0

    Response:

    {"draw":1,"recordsTotal":4,"recordsFiltered":25,"data":[["Hunain","123"],["hk","asd"],["daenerys Targaryen"
    ,"123"],["",""]]}

    After performing a search:

    Request:

    _
    1503560409319
    columns[0][data]
    0
    columns[0][name]
    columns[0][orderable]
    true
    columns[0][search][regex]
    false
    columns[0][search][value]
    columns[0][searchable]
    true
    columns[1][data]
    1
    columns[1][name]
    columns[1][orderable]
    true
    columns[1][search][regex]
    false
    columns[1][search][value]
    columns[1][searchable]
    true
    draw
    2
    length
    10
    order[0][column]
    0
    order[0][dir]
    asc
    search[regex]
    false
    search[value]
    w
    start
    0

    Response:

    {"draw":1,"recordsTotal":1,"recordsFiltered":25,"data":[["Waleed","123"]]}

  • HunaynHunayn Posts: 7Questions: 2Answers: 0

    @tangerine that didn't work man, thanks btw

  • HunaynHunayn Posts: 7Questions: 2Answers: 0

    It's done. Thanks for the help guys.

    The reason was that draw parameter being sent and received was not same because I took draw static in the server code so mismatched. I returned the same draw parameter as it was sent.

  • allanallan Posts: 63,214Questions: 1Answers: 10,415 Site admin
    Answer ✓

    Request
    draw 2

    but

    Response
    "draw":1

    That's the problem. From the documentation:

    draw: The draw counter that this object is a response to - from the draw parameter sent as part of the data request. Note that it is strongly recommended for security reasons that you cast this parameter to an integer, rather than simply echoing back to the client what it sent in the draw parameter, in order to prevent Cross Site Scripting (XSS) attacks.

    Allan

  • allanallan Posts: 63,214Questions: 1Answers: 10,415 Site admin
    Answer ✓

    p.s. If you only have 25 records in the table, don't use server-side processing. You should only consider server-side processing when you had thousands of rows, since otherwise you are just introducing latency into your application. Even then, I would typically only recommend it when you are working with tens of thousands of rows.

    Allan

This discussion has been closed.