Last active
July 13, 2017 14:45
-
-
Save timw255/bb45a2a63f9470284aab3b9ad5768671 to your computer and use it in GitHub Desktop.
Use a Kendo DataSource as the driver for a Kendo Grid, or any other Kendo Component, in a Rollbase Application. (Hierarchical)
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<div id="treeview"></div> | |
<script> | |
$(function() { | |
var children = { | |
transport: { | |
read: function (options) { | |
var columns = []; | |
for (var key in children.schema.model.fields) { | |
columns.push(key); | |
} | |
rbf_getRelatedIds(hierarchicalDataSource.options.schema.relName, options.data.id, function(relName, id, values) { | |
var query = 'SELECT ' + columns.join(',') + ' FROM ' + children.schema.objName + ' WHERE id IN (' + values.join(',') + ')'; | |
rbf_selectQuery(query, 200, function(values) { | |
options.success(values); | |
}); | |
}) | |
} | |
}, | |
schema: { | |
objName: 'Related_Sample_Object', | |
model: { | |
id: 'id', | |
fields: { | |
id: {}, | |
name: {} | |
}, | |
hasChildren: function (item) { | |
return false; | |
}, | |
}, | |
parse: function(response) { | |
var data = []; | |
var columns = []; | |
for (var key in children.schema.model.fields) { | |
columns.push(key); | |
} | |
for (var i = 0; i < response.length; i++) { | |
var obj = {}; | |
for (var c = 0; c < columns.length; c++) { | |
obj[columns[c]] = response[i][c]; | |
} | |
data.push(obj); | |
} | |
return data; | |
} | |
} | |
}; | |
var hierarchicalDataSource = new kendo.data.HierarchicalDataSource({ | |
transport: { | |
read: function (options) { | |
var columns = []; | |
for (var key in hierarchicalDataSource.options.schema.model.fields) { | |
columns.push(key); | |
} | |
var query = 'SELECT ' + columns.join(',') + ' FROM ' + hierarchicalDataSource.options.schema.objName; | |
rbf_selectQuery(query, 200, function (values) { | |
options.success(values); | |
}); | |
} | |
}, | |
schema: { | |
objName: 'Sample_Object', | |
relName: 'R24109', | |
model: { | |
id: 'id', | |
fields: { | |
id: {}, | |
name: {}, | |
R24109: {} | |
}, | |
hasChildren: 'children', | |
children: children | |
}, | |
parse: function(response) { | |
var data = []; | |
var columns = []; | |
for (var key in hierarchicalDataSource.options.schema.model.fields) { | |
columns.push(key); | |
} | |
for (var i = 0; i < response.length; i++) { | |
var obj = {}; | |
for (var c = 0; c < columns.length; c++) { | |
obj[columns[c]] = response[i][c]; | |
} | |
data.push(obj); | |
} | |
return data; | |
} | |
}, | |
pageSize: 10 | |
}); | |
$('#treeview').kendoTreeView({ | |
dataSource: hierarchicalDataSource, | |
dataTextField: 'name' | |
}); | |
}); | |
</script> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment