dimanche 24 avril 2016

FancyTree persist plugin not remembering unselected checkboxes

I'm creating a fancytree (http://ift.tt/18W0CYD) using the following code:

    $("#tree").fancytree({
    checkbox: true, // Show checkboxes.
    extensions: ["persist"],
    persist: {
        overrideSource: true,
        store: "cookie"
    },
    source: $.ajax({
        url: "treedata",
        type: "POST",
        dataType: "json"
    }),
    selectMode: 3,
    icons: false
});

The ajax call to get the "treedata" is populated so that each node is selected by default, e.g.

[{"title":"All",
"key":"ALL",
"folder":true,
"expanded":true,
"selected":true,
"children":[{"title":"Africa",
    "key":"AFRICA",
    "folder":true,
    "expanded":false,
    "selected":true,
        "children":[{"title":"Algeria",
        "key":"ALGERIA",
        "folder":false,
        "expanded":false,
        "selected":true,
        "children":null}
        ...

Then, a user can choose to unselect some of the checkboxes as they see fit. This allows all details to be returned on initial page load, but only the details for the ticked checkboxes to be returned on a subsequent search.

What I am unable to do, is to correctly store which details have been unselected by the user. I've looked into the fancytree code and can see that the cookie is storing the details that are selected, not the details that are unselected. This means that the persist extension will correctly "overrideSource" to remember which nodes are expanded, but will only "overrideSource" to remember which nodes need selecting - it does not "overrideSource" to remember which nodes need unselecting.

Is there a way in which all nodes can be selected by default on initial page load, whilst also using the persist plugin to correctly remember which nodes need to be unselected?

Thanks




Aucun commentaire:

Enregistrer un commentaire