jeudi 25 juillet 2019

How to store and retrieve checked treeview checkbox in using localstorage or cookies?

I have a hierarchical structured treeview with checkboxes and i would like to store the checked checkbox into either localstorage or cookies then retrieved it back. It work fine with normal checkbox but not when combined treeview and checkbox.

JavaScript for localStorage

jQuery(function()
     {if (localStorage.input)
        {var checks = JSON.parse(localStorage.input);
            jQuery(':checkbox').prop('checked', function(i)
              {return checks[i];
              });
            }
    });

    jQuery(':checkbox').on('change', function() 
    {localStorage.input = JSON.stringify(jQuery(':checkbox').map(function()
        { this.checked;
        }).get());
   });

JavaScript for Kendo Treeview with checkbox

homogeneous = new kendo.data.HierarchicalDataSource({
                    transport: {
                        read: {
                            url: serviceRoot,
                            dataType: "json"
                        }
                    },
                    schema: {
                        model: {
                            id : "ehorsProgramID",
                            hasChildren: false,
                            children : "items"
                        }
                    },

                    filter: { field: "module", operator: "startswith", value: "Accounting" }
                });

            $("#AccountingTree").kendoTreeView({
                check: onCheck,
                checkboxes: { checkChildren: true } ,
            //  select: onSelect,
                dataSource: homogeneous,
                    dataBound: function(){
                        this.expand('.k-item');
                    },
                dataTextField: ["module","groupname","ehorsProgramName"]
            });

Anyone have opinion on this?




Aucun commentaire:

Enregistrer un commentaire