addon/net

Add-on for binding to remote data

Parameters:
Name Type Description
options object
Properties
Name Type Attributes Default Description
el jquery <optional>

Form element (to be used for ajax request)

initialRequest boolean <optional>
true

Whether to request 'readData' after initialized

readDataMethod string <optional>
'POST'

Http method to be used for 'readData' API ('POST' or 'GET')

api object <optional>

URL map

Properties
Name Type Attributes Description
readData string <optional>

URL for read-data

createData string <optional>

URL for create

updateData string <optional>

URL for update

modifyData string <optional>

URL for modify (create/update/delete at once)

deleteData string <optional>

URL for delete

downloadExcel string <optional>

URL for download data of this page as an excel-file

downloadExcelAll string <optional>

URL for download all data as an excel-file

perPage number <optional>
500

The number of items to be shown in a page

enableAjaxHistory boolean <optional>
true

Whether to use the browser history for the ajax requests

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