SMART datagrid v.1 > Examples

Back  Forward

Load Csv Data  Example

In most applications, they get the initial data from the server and fill them in the grid. There are many formats of data sent from the server, and in this example, we will learn the data saved as CSV format. 

Commonly, a text file which has one or more rows with the values separated by comma is called a CSV file. The separator can be a tab key or another character rather than comma, or the values can also be enclosed with double quotes. In addition, the first few rows may be covered by the meta information about the entire data, such as column name lists rather than the actual data rows. 

In response to all cases above, DataLoader of SMART datagrid can get the data saved as CSV file to the data set rows of the grid. Please refer to load method about the details. 

Code -1
    $.ajax({
    	url: "/repo/grid/resource/data/orders.csv",
    	dataType: 'text',
    	success: function (data) {
            new DataLudi.DataLoader(dsMain).load("csv", data, {
            	start: 1,   // Read from the second row as data rows.
            	count: 500  // Read 500 rows as a maximum.
            });
    	}
    });
Grid - 1
rows

When load the data from the server to DataSet by calling DataLoader.load, all the existing data will be removed and new one will be filled in. However, if call load, the existing data can be modified or added depending on fillMode settings. 

Code -2
    $.ajax({
    	url: "/repo/grid/resource/data/orders.csv",
    	dataType: 'text',
    	success: function (data) {
            var row = grdMain.focusedIndex().rowIndex;
            if (row < 0) row = 0;

            new DataLudi.DataLoader(dsMain).load("csv", data, {
            	start: 1,
            	count: 500,
            	fillMode: 'insert', // 'insert', 'append', 'update', the default is 'set'
            	fillPos: row
            });
    	}
    });

If click the buttons below, it will load 5 rows and insert respectively in the current row location, or add after the last row, or modify 5 rows from the current row location. 

Grid - 2
rows

View Source JSP 

See Also
GridView
Examples
Load JSON Data
Load XML Data