I have two dialog boxes within my view. Each of these dialog boxes have ajax commands within them for instance the first one does a POST
and second one does a LOAD
.
The issue is after I select from a checkbox list in dialog box 1 and hit UpdatePage button, my model gets updated just fine. However, The second dialog box containing the tree view with another checbobox list/nodes will not toggle at all. It does retain its previous state though: The checkboxes selected previosuly are checked but it will not toggle at all.
The following function creates the dialog box 1 and upon successful completion of the post command in this dialog box that the second dialog box and the treeview within, will not toggle.
function initDailog() {
RunDialog = $("#runDatestreeview").dialog({ closeOnEscape: true, stack: false, autoOpen: true,
modal: false, resizable: true, draggable: true, title: 'Select Run Dates to Auto-Populate Form Fields & Test Exceptions:',
width: 600, height: 500, position: 'center',
open: function (type, data) {
},
buttons: { UpdatePage: function () {
//storing the value of treeview selections in dialog box 2
var originalContent = $("#treeview").html();
$.post(runDatesUrl,
$("#form").serialize(),
function (data) {
$("#runDatestreeview").remove();
//removing the div which contains the treeview
$("#treeview").remove();
$("#testExceptiontreeview").remove();
$("#main").html(data);
//setting back the value of the div which contains the treeview
$("#treeview").html(originalContent);
}, "html");
},
Cancel: function () {
$(this).dialog("close");
}
}
});
RunDialog.closest("div.ui-dialog").appendTo("#form");
}
Treeview defined in dialog box 2, in its seperate JS file:
$("#errorCodes ul").treeview({
collapsed: true,
prerendered: false
});
The HTML for The div which contains the tree view:
<div id="treeview" title="Dialog Title" style="font-size: 10px; font-weight: normal;
overflow: scroll; width: 800px; height: 450px; display: none;">
<div id="errorCodes">
@Html.RenderTree(CacheHelper.ErrorCodes(), ec => ec.Name, ec => ec.Children.ToList(), ec => (ec.ID).ToString(), null, "e")
</div>
<div id="inputReps" style="display: none;">
</div>
</div
I have had a play-around with this and if you store the
.html()
and then after adding it again, re-bind the plugin again, the state is kind-off remembered.I used the code from the fiddle I created for your last question and slightly updated it.
DEMO - Store HTML, remove Tree, Add new Tree, set HTML and rebind treeView
In the above DEMO I'm binding the treeview on load, collapse/expand the tree view and then hit the
store/remove/attach
button. After that the tree looks as before and collapse/expand/toggle still work.The
store/remove/attach
button will do the following when clicked:ul
element which is the treeviewul
elementul
elementul
ul
to the treeview pluginIt remembers the state, if the tree was collapsed, it renders collapsed and expanded it renders expanded.
Except for the default closed element (File 3) as the
close
class will be re-applied the first time it renders.Other than that it looks OK.
Code from DEMO
HTML
Script
CSS