Loading Rollbase Data into KendoUI Datasource

Posted by Frank S on 15-Oct-2015 08:53

Would someone be able to provide an example of the best way to load data from a Rollbase object into the KendoUI datasource so that it's usable within a widget? The specific example we're trying to build out is to use the TreeList widget to show records related to an object. Is this best done through the browser API or is there a better way?

Thanks in advance for your help!

Posted by ymaisonn on 15-Oct-2015 13:49

Example to generate JSON content within the trigger (list of contacts):

var country = "Netherlands";
var myArray = new Array();
var resultSet = rbv_api.selectQuery("SELECT firstName, lastName, country from customer WHERE country = ?", 1000, country)
 
for (int idx =0; i< resultSet.length; i++){
myArray.push({"firstName": resultSet[i][0], "lastName": resultSet[i][1], "country": resultSet[i][2]});
}
 
var myStringifiedJSON = rbv_api.jsonToString(myArray);
 
return myStringifiedJSON;

)

All Replies

Posted by ymaisonn on 15-Oct-2015 13:35

An approach would be to create a JSON object of the data you aim to pass to the widget, serialize it as a string and store it in a text field  using either

- JSON.stringify(myArray)

or

- rbv_api.jsonToString(myArray)

(both methods do the same thing)

You can implement this logic in a trigger

The second step  is to add your Widget code in a page inside a "Script component" in which you will also retrieve the field value storing the stringified JSON, and perform the inverse operation:

var datasource = JSON.parse('{!myStringifiedJSON}');

or

var datasource = rbv_api.stringToJson('{!myStringifiedJSON}')

You have now a datasource as a javascript array which you can pass to your widget.

Posted by ymaisonn on 15-Oct-2015 13:49

Example to generate JSON content within the trigger (list of contacts):

var country = "Netherlands";
var myArray = new Array();
var resultSet = rbv_api.selectQuery("SELECT firstName, lastName, country from customer WHERE country = ?", 1000, country)
 
for (int idx =0; i< resultSet.length; i++){
myArray.push({"firstName": resultSet[i][0], "lastName": resultSet[i][1], "country": resultSet[i][2]});
}
 
var myStringifiedJSON = rbv_api.jsonToString(myArray);
 
return myStringifiedJSON;

)

Posted by ymaisonn on 15-Oct-2015 13:56

.

This thread is closed