javascript - Kendo UI treeview current datasource post -
i need create folder structure in ftp similar of tree structure on view. want allow user edit tree structure before creating folders.
i have treeview server binding:
@model ienumerable<treeviewitemmodel> @(html.kendo().treeview() .name("pipelinestructuremajor") .bindto(model) .expandall(true) .draganddrop(true) )
the binding fine. client-side restructuring (appending/dragging/removing nodes), want post treeview (root node children recursively) action.
public actionresult _createftp(treeviewitemmodel root) { //ftpclient in action : parsing whole tree , converting folder structure return partialview("_treemajor", <refreshed model>); }
on client side, tried alert treeview data, shows root node text items empty.
$('#createftpconfirmed').click(function () { //treeview data var treedata = $("#pipelinestructuremajor").data("kendotreeview").datasource.data(); alert(json.stringify(treedata)); $.ajax({ url:'@url.action("_createftp", "structure")', data: {root: treedata}, type:"post", success: function (result, status, xhr) { //doing useful } }); });
is there way accomplish this?
as question explains, have 3 steps:
- server-bind default tree
- edit nodes (delete, add, rename nodes)
- fetch treeview data (including added ones)
after going through kendo docs , this demo, got point. have make tree datasource observable reflect node-changes. had use kendo-web-scripts (instead of server wrappers). changed step 1 to:
- remote bind default tree (to make datasource observable)
i want tree view loaded @ once remotely , seeing demo, figured out treeview allows 1 level loaded @ time. (uservoice queued kendo team still ignoring it). use hacky way:
<div id="pipelinestructuremajor"></div> <button id="createandorinsert" class="k-button hugebtn">send</button> <script> $.get("../structure/loadtreedata", function (data) { var sat = new kendo.data.hierarchicaldatasource({ data: data }); var pipelinetree = $("#pipelinestructuremajor").kendotreeview({ datasource: kendo.observablehierarchy(sat), dragdrop: true, select: onnodeselect }).data("kendotreeview"); }); </script>
and sent data controller action like:
$('#createandorinsert').click(function (e) { //treeview's current datasource var tree = $("#pipelinestructuremajor").data("kendotreeview").datasource.data(); $.ajax({ url: '../structure/ftpcreateandorsync', type: 'post', data: { xmlnodes: json.stringify(tree) }, beforesend: function (xhr) { alertspan.removeclass().addclass("loading"); }, success: function (result, status, xhr) { alertspan.removeclass().addclass("success"); }, error: function (jqxhr, textstatus, errorthrown) { alertspan.removeclass().addclass("error"); } });
});
and on controller side, deserialized string json as: showing partial code
[acceptverbs(httpverbs.post)] public actionresult ftpcreateandorsync(string xmlnodes) { //deserializing nodes var xmlnodesmodels = new system.web.script.serialization.javascriptserializer().deserialize<ienumerable<xmlnode>>( xmlnodes).toarray(); ////alternative //var data = jsonconvert.deserializeobject<ienumerable<xmlnode>>(xmlnodes); return json(new { cr = createresult, dr = dbresult }); }
hope helps someone.
Comments
Post a Comment