jquery-datatables-checkboxes savestate question

jquery-datatables-checkboxes savestate question

lenamtllenamtl Posts: 265Questions: 65Answers: 1
edited January 2020 in Free community support

Hi,

I'm using https://github.com/gyrocode/jquery-datatables-checkboxes/

And trying to save the statesave

In console.log on page load, there is no checkbox selected
using stateSaveCallback or stateSaveParams

the result for the checkbox state is

checkboxes: (2) [empty, {…}]
checkboxes: Array(2)
1: {}
length: 2
__proto__: Array(0)

I guess the problem come from this [empty, {…}] instead of displayed this [{…}]
I'm sending the table state like this "tablestate": JSON.stringify(data)
because I'm saving the state into DB and only the checkbox statevalues are not saved the other Datatables are saved ok

I'm using Datatables 1.10.11 (cannot update to latest for now)
Any idea what is going wrong and recommendation to fix this.

Answers

  • colincolin Posts: 15,143Questions: 1Answers: 2,586

    Is this the same issue as you reported here?

  • lenamtllenamtl Posts: 265Questions: 65Answers: 1
    edited January 2020

    No it is not related (previous question was related to info true or false)
    Now this is different issue related to stateSaveCallback or stateSaveParams

    as for some reasons the values are not saved
    I'm getting [empty, {…}]instead of this[{…}]

    I'm wondering if something is wrong with query-datatables-checkboxes and the state when use with stateSaveCallback or stateSaveParams

    I'm sending Datatables state like this and it's working fine with all Datatables States (except with the query-datatables-checkboxes)
    "tablestate": JSON.stringify(data)

  • allanallan Posts: 61,716Questions: 1Answers: 10,108 Site admin

    Your best bet is to get in touch with Gyrocode, the original author of that library. Its third party and not written nor supported by ourselves I'm afraid.

    Allan

  • lenamtllenamtl Posts: 265Questions: 65Answers: 1

    Hi Allan,

    Yes I understand, I already have contacted him.
    https://github.com/gyrocode/jquery-datatables-checkboxes/issues/107

    Now I know how to reproduce the problem...

    Here is an example https://jsfiddle.net/lenamtl/a8jurbp1/

    The problem seems to occured when using column 1 for the checkbox

    The result in console is
    stateLoaded
    checkboxes: (2) [null, {…}]

    stateSaveParams
    checkboxes: (2) [empty, {…}]

    and that should be [{…}]

    I just take a chance that maybe another dev encounter the same issue and have a solution

  • lenamtllenamtl Posts: 265Questions: 65Answers: 1
    edited January 2020

    Hi,

    I need to figure out based on this result

    stateLoaded
    checkboxes: (2) [null, {…}]

    stateSaveParams
    checkboxes: (2) [empty, {…}]

    is this normal to have a **null **and **empty **value ?

    Does Datatables can manage it or not?

    That will help me to investigate...
    I never see any null or empty value in the state result with the plugins i'm using ..

    Thanks

  • kthorngrenkthorngren Posts: 20,302Questions: 26Answers: 4,769

    Datatables doesn't manage what or how the plugins save the state. Your example seems to work and loads the checkbox states appropriately. Is there a problem I'm not seeing? Does the null or empty array position affect something in your code?

    If you want to investigate you can open the checkboxes plugin source code and find where its saving the state.

    Kevin

  • lenamtllenamtl Posts: 265Questions: 65Answers: 1

    The state of the checkboxes are not save at all but the rest of the tables state aretsaved correctly.

    I'm sending the table state like this "tablestate": JSON.stringify(data)

  • kthorngrenkthorngren Posts: 20,302Questions: 26Answers: 4,769
    edited January 2020

    The state of the checkboxes are not save at all but the rest of the tables state aretsaved correctly.

    Does the example you posted not work not work for you?
    https://jsfiddle.net/lenamtl/a8jurbp1/

    It works for me.

    I'm sending the table state like this "tablestate": JSON.stringify(data)
    because I'm saving the state into DB and only the checkbox statevalues are not saved the other Datatables are saved ok

    Sounds like the basic Datatables and Gyrocode checkboxes functionality works with stateSave. But when you send to the server something server side doesn't like the null in the array. According to jsonlint the JSON string generated with the null array element in stateSaveCallback is valid with this result:

    {
        "time": 1580416235127,
        "start": 0,
        "length": 10,
        "order": [
            [1, "asc"]
        ],
    
        .....
    
        "checkboxes": [null, {
            "2": 1
        }]
    

    Sounds like maybe something on the server side isn't handling this correctly. Have you looked there to see what is happening there?

    What is the JSON response from the server?

    Kevin

  • lenamtllenamtl Posts: 265Questions: 65Answers: 1
    edited January 2020

    After several tests I finally found the problem

    I have made a new jsfiddle that reproduce the problem using basic localstorage saved in browser
    https://jsfiddle.net/lenamtl/ujqx9Lhc/1/

    It appear that the problem occurred when using checkboxes in combinaison with Yadcf Datatables plugins...

  • colincolin Posts: 15,143Questions: 1Answers: 2,586

    That's a third-party extension so it would be worth raising with the author.

    Colin

  • lenamtllenamtl Posts: 265Questions: 65Answers: 1

    Yes I know
    I was investigating ...

    I'm just trying to find out if someone have the same issue and maybe found a solution.

This discussion has been closed.