SMART datagrid v.1 > Classes > DataLoader

Back  Forward

DataLudi.DataLoader.load  method

Read text or JSON object or XML to add it as the data rows of Data Set

According to type, the way of handling data and the property which can be set in options will be different. It will be described in the table below. Please refer to "Fill Mode" table about "fillMode", "fillPos" among options. 

function load (type: String, data: Object|String, options: Object): Number;
Returns
Number
Parameters
type - String. required.
data - Object|String. required.
options - Object. required.
Table-1  Data Load
typedataoptions
'csv'text'start': The start row location which will be read as data. The default value is 0.
'count': The number of rows which will be read. If less than 0, it will be from start to all rows. The default value is -1.
'delimiter': Field delimiter. The default value is ','.
'quoted': If it is true, when enclosed by '"'(double quote) or '''(single quote), it will read after removing two ends.
'currency': If it is true, in the case of NUMBER field, it will read the characters after removing number, '.', '-', '+'.
'filter': Filter expression which will be applied when fillMode is not 'update'. It will read only the rows which have passed this expression.
Please refer to below Filter variables about the variables which can be used in expression.
Example) It will read only the lines of which 'values['product_id'] like 'n%'' => product_id starts with 'n'.
'json'text | jsonIn the case of text, it will objectify by JSON.parse().
'start': The start row location which will be read as data. The default value is 0.
'count': The number of rows which will be read. If less than 0, it will be from start to all rows. The default value is -1.
'rows': The location of data set which will be read as row among data. It is specified as the path which is separated by comma. Please refer to Json Path table below. If do not specify, it will consider data as JSON array.
'filter': It is the same as CSV item above.
'xml'text | DOMIn the case of text, it will use DOMParser or ActiveXObject to run parsing as XMLDocument object first.
'start': The start row location which will be read as data. The default value is 0.
'count': The number of rows which will be read. If less than 0, it will be from start to all rows. The default value is -1.
'rows': The location of data set which will be read among data. It is specified as the path which is separated by comma. Please refer to Xml Path table below. If do not specify, it will consider data as JSON array.
'filter': It is the same as CSV item above.
Table-2  Fill Mode
fillModeExplanation
'set'Fill after removing the existing rows.
'append'Append after the last row.
'insert'Insert in fillPos location.
'update'Overwrite from fillPos location.
Table-3  JSON Path
pathExplanation
''If do not specify or it is an empty string, it will read the original data as array.
'row'It will read 'row' property of original data as array.
'prop.row'It will read 'row' property of 'prop' property of original data as array.
'prop[1].row''prop' property of original data is array, and it will read 'row' property of the second object as array.
'$[0].row'Original data is array, and it will read 'row' property of the first object as array.
Table-4  XML Path
pathExplanation
''If do not specify or it is an empty string, it will not be able to read as data rows. If do not specify, it will get the elements of which name is 'row'.
'row'It will read the ones of which name is 'row' among the top elements as row.
'prop.row'It will read the ones of which name is 'row' among sub elements of the first element among the top elements of which name is 'prop' as row.

It is the same as specifying by 'prop[0].row'.
'prop[1].row'It will read the ones of which name is 'row' among sub elements of the second element among the top elements of which name is 'prop' as row.
'$[0].row'Original data is array, and it will read 'row' property of the first object as array.
Table-5  Filter variables
Variable nameExplanation
'no'The location of original row which is being read now. start value will be added.
'row'The number of data set row which is being appended or updated.
'values'The field value of original row. It will be used as 'values['product_id']'.
Code -1
    $('#load').click(function () {
        $.getJSON('data/data.json', null, function (data) {
    		new DataLudi.DataLoader(dataset).load('json', data, {
    		    fillMode: "append"
    		});
    		// or, use total function.
    		DataLudi.loadJsonData(dataset, data, {
    		    fillMode: "update",
    		    fillPos: 10,
    		});
    	});
    });
See Also
DataSet
Examples
Load CSV Data
Load JSON Data
Load XML Data