Skip to content

Commit

Permalink
make enough space for users to build up their ajax requests
Browse files Browse the repository at this point in the history
  • Loading branch information
dabeng committed Dec 1, 2023
1 parent 3c0b089 commit 38a2449
Show file tree
Hide file tree
Showing 6 changed files with 36 additions and 46 deletions.
6 changes: 3 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -249,10 +249,10 @@ var oc = $('#chartContainerId').orgchart(options);
<tbody>
<tr>
<td>data</td>
<td>json or string</td>
<td>json</td>
<td>yes</td>
<td></td>
<td>datasource usded to build out structure of orgchart. It could be a json object or a string containing the URL to which the ajax request is sent.</td>
<td>datasource usded to build out structure of orgchart. It should be a json object.</td>
</tr>
<tr>
<td>pan</td>
Expand Down Expand Up @@ -413,7 +413,7 @@ var oc = $('#chartContainerId').orgchart(options);
<td>function</td>
<td>no</td>
<td></td>
<td>It can often be useful to know when your table has fully been initialised, data loaded and rendered, particularly when using an ajax data source. It receives one parament: "$chart" stands for jquery object of initialised chart.</td>
<td>It can often be useful to know when your table has fully been initialised, data loaded and rendered. It receives one parament: "$chart" stands for jquery object of initialised chart.</td>
</tr>
<tr>
<td>icons</td>
Expand Down
28 changes: 24 additions & 4 deletions demo/ajax-datasource.html
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,16 @@
<link rel="icon" href="img/logo.png">
<link rel="stylesheet" href="css/jquery.orgchart.css">
<link rel="stylesheet" href="css/style.css">
<style type="text/css">
.spinner {
line-height: 420px;
}
.spinner::before {
width: 72px;
height: 72px;
border-radius: 36px;
}
</style>
</head>
<body>
<div id="chart-container"></div>
Expand Down Expand Up @@ -46,10 +56,20 @@
}
});

$('#chart-container').orgchart({
'data' : '/orgchart/initdata',
'nodeContent': 'title'
});
$('#chart-container').append(`<i class="oci oci-spinner spinner"></i>`);
$.ajax({
'url': '/orgchart/initdata',
'dataType': 'json'
})
.done(function(data, textStatus, jqXHR) {
$('#chart-container').orgchart({
'data': data,
'nodeContent': 'title'
});
})
.always(function() {
$('#chart-container').children('.spinner').remove();
});

});
</script>
Expand Down
19 changes: 2 additions & 17 deletions dist/js/jquery.orgchart.js
Original file line number Diff line number Diff line change
Expand Up @@ -76,28 +76,13 @@
this.triggerInitEvent();
}
var $root = $chart.append($('<ul class="nodes"><li class="hierarchy"></li></ul>')).find('.hierarchy');
if ($.type(data) === 'object') {

if (data instanceof $) { // ul datasource
this.buildHierarchy($root, this.buildJsonDS(data.children()), 0, this.options);
} else { // local json datasource
this.buildHierarchy($root, this.options.ajaxURL ? data : this.attachRel(data, '00'));
}
} else {
$chart.append(`<i class="${this.options.icons.theme} ${this.options.icons.spinner} spinner"></i>`);
$.ajax({
'url': data,
'dataType': 'json'
})
.done(function(data, textStatus, jqXHR) {
that.buildHierarchy($root, that.options.ajaxURL ? data : that.attachRel(data, '00'), 0, that.options);
})
.fail(function(jqXHR, textStatus, errorThrown) {
console.log(errorThrown);
})
.always(function() {
$chart.children('.spinner').remove();
});
}

$chartContainer.append($chart);

// append the export button
Expand Down
8 changes: 4 additions & 4 deletions dist/js/jquery.orgchart.min.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion dist/js/jquery.orgchart.min.js.map

Large diffs are not rendered by default.

19 changes: 2 additions & 17 deletions src/js/jquery.orgchart.js
Original file line number Diff line number Diff line change
Expand Up @@ -76,28 +76,13 @@
this.triggerInitEvent();
}
var $root = $chart.append($('<ul class="nodes"><li class="hierarchy"></li></ul>')).find('.hierarchy');
if ($.type(data) === 'object') {

if (data instanceof $) { // ul datasource
this.buildHierarchy($root, this.buildJsonDS(data.children()), 0, this.options);
} else { // local json datasource
this.buildHierarchy($root, this.options.ajaxURL ? data : this.attachRel(data, '00'));
}
} else {
$chart.append(`<i class="${this.options.icons.theme} ${this.options.icons.spinner} spinner"></i>`);
$.ajax({
'url': data,
'dataType': 'json'
})
.done(function(data, textStatus, jqXHR) {
that.buildHierarchy($root, that.options.ajaxURL ? data : that.attachRel(data, '00'), 0, that.options);
})
.fail(function(jqXHR, textStatus, errorThrown) {
console.log(errorThrown);
})
.always(function() {
$chart.children('.spinner').remove();
});
}

$chartContainer.append($chart);

// append the export button
Expand Down

0 comments on commit 38a2449

Please sign in to comment.