Add-on for binding to remote data
Parameters:
Name | Type | Description | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
options |
object |
Properties
|
Example
<form id="data_form">
<input type="text" name="query"/>
</form>
<script>
var net;
var grid = new tui.Grid({
//...options...
});
// Activate 'Net' addon
grid.use('Net', {
el: $('#data_form'),
initialRequest: true,
readDataMethod: 'GET',
perPage: 500,
enableAjaxHistory: true,
api: {
'readData': './api/read',
'createData': './api/create',
'updateData': './api/update',
'deleteData': './api/delete',
'modifyData': './api/modify',
'downloadExcel': './api/download/excel',
'downloadExcelAll': './api/download/excelAll'
}
});
// Bind event handlers
grid.on('beforeRequest', function(data) {
// For all requests
}).on('response', function(data) {
// For all response (regardless of success or failure)
}).on('successResponse', function(data) {
// Only if response.result is true
}).on('failResponse', function(data) {
// Only if response.result is false
}).on('errorResponse', function(data) {
// For error response
});
net = grid.getAddOn('Net');
// Request create
net.request('createData');
// Request update
net.request('updateData');
// Request delete
net.request('deleteData');
// Request create/update/delete at once
net.request('modifyData');
</script>
Methods
-
download(type)
-
Change window.location to registered url for downloading data
Parameters:
Name Type Description type
string Download type. 'excel' or 'excelAll'.
Will be matched with API 'downloadExcel', 'downloadExcelAll'. -
readData(page, data, resetData)
-
Requests 'readData' to the server. The last requested data will be extended with new data.
Parameters:
Name Type Description page
Number Page number
data
Object Data(parameters) to send to the server
resetData
Boolean If set to true, last requested data will be ignored.
-
reloadData()
-
Requests 'readData' with last requested data.
-
request(requestType, options) → {boolean}
-
Send request to server to sync data
Parameters:
Name Type Description requestType
String 'createData|updateData|deleteData|modifyData'
options
object Options
Properties
Name Type Attributes Default Description url
String <optional>
URL to send the request
hasDataParam
String <optional>
true Whether the row-data to be included in the request param
checkedOnly
String <optional>
true Whether the request param only contains checked rows
modifiedOnly
String <optional>
true Whether the request param only contains modified rows
showConfirm
String <optional>
true Whether to show confirm dialog before sending request
updateOriginal
String <optional>
false Whether to update original data with current data
Returns:
boolean -Whether requests or not
-
setPerPage(perPage)
-
Set number of rows per page and reload current page
Parameters:
Name Type Description perPage
number Number of rows per page