-
Config
- barHeight
-
bbar
- bbarHeight
- bbarHidden
-
buttons
- buttonsHeight
- buttonsHidden
- cellHeaderHeight
- cellHeight
- cellStylingCls
- cellTrackOver
- cellWrapper
- clicksToEdit
- cls
- columnClickData
- columnLines
-
columns
- autoWidth
- align
- autoHeight
- cellAlign
- cellTip
- cls
- columns
-
data
- disallowAfterDrop
- displayKey
- draggable
- editable
- ellipsis
- exportFn
- exportable
-
filter
- flex
- format
- headerCheckBox
- headerClickSort
- headerCls
- headerCellTip
- headerLImageCls
- hidden
- id
- index
- itemCheckBox
-
items
- leftTpl
- leftWidth
- listItemTpl
- lockable
- locked
- maxWidth
- menu
- minEditorWidth
- minListWidth
- minWidth
- multiSelect
- precision
- render
- resizable
- rightLocked
- rowdrag
- searchable
- select
- selectable
- smartIndexFn
- sortable
- sorter
- sparkConfig
- spin
- step
- subSearch
- summary
- title
- titleEditable
- type
- valueKey
- values
- vtype
- width
- controllers
- columnTrackOver
- contextmenu
-
data
- defaults
- dirtyEnabled
- draggable
- droppable
- dropZone
- dropZoneFn
- doubleHorizontalScroll
- emptyText
-
events
- activate
- beforeedit
- beforeendedit
- cellclick
- celldblclick
- cellenter
- cellleave
- change
- changepage
- changepagesize
- columnclick
- columndblclick
- columndrag
- columnenter
- columnhide
- columnleave
- columnshow
- columnresize
- columntitlechange
- deactivate
- delay
- deselectrow
- dragrows
- dropitems
- endedit
- filter
- init
- insert
- headercellclick
- headercellenter
- headercellleave
- load
- lockcolumn
- remove
- rowclick
- rowdblclick
- rowenter
- rowleave
- select
- selectrow
- servererror
- set
- scope
- sort
- startedit
- unlockcolumn
- update
-
expander
- exporter
-
filter
- flexScrollSensitive
-
footer
-
gridToGrid
-
grouping
- height
- id
- infinite
- i18n
-
lang
- autoSizeColumn
- autoSizeColumns
- cancel
- columns
-
date
- decimalSeparator
- dragText
- loadingText
- lock
- no
- paging
- loadMask
- minHeight
- minWidth
- modal
- multiSort
- multiSortLimit
- nativeScroller
- paging
- renderOuter
- renderTo
- resizable
- rowEdit
- rowLines
- searching
- selModel
- shadow
- singleExpand
- state
- startEditByTyping
- stateful
- stateId
- striped
- subTBar
- allowToggle
- action
- cls
- data
- disabled
- displayKey
- editable
- emptyText
- enableToggle
- events
- format
- handler
- hidden
- id
- imageCls
- inputHeight
- itemCheckBox
- leftTpl
- leftWidth
- max
- menu
- minListWidth
- multiSelect
- multiToggle
- paramsMenu
- paramsText
- pressed
- spin
- step
- subSearch
- text
- tip
- toggleGroup
- type
- valueKey
- vtype
- width
- subTBarHeight
- subTBarHidden
- subHeaderFilter
- subTitle
- summary
- tabScrollStep
- tbar
- action
- allowToggle
- cls
- data
- disabled
- displayKey
- editable
- emptyText
- enableToggle
- events
- format
- handler
- hidden
- id
- imageCls
- inputHeight
- itemCheckBox
- leftTpl
- leftWidth
- max
- menu
- min
- minListWidth
- multiSelect
- multiToggle
- paramsMenu
- paramsText
- pressed
- spin
- step
- subSearch
- text
- tip
- toggleGroup
- type
- valueKey
- vtype
- width
- tbarHeight
- tbarHidden
- textSelection
- theme
- title
- Columns
- Events
- activate
- beforeedit
- beforeendedit
- cellclick
- celldblclick
- cellenter
- cellleave
- change
- changepage
- changepagesize
- columnclick
- columndblclick
- columndrag
- columnenter
- columnhide
- columnleave
- columnshow
- columnresize
- columntitlechange
- contextmenu
- deactivate
- deselectrow
- dragrows
- dropitems
- endedit
- filter
- init
- insert
- headercellclick
- headercellenter
- headercellleave
- load
- lockcolumn
- remove
- rowclick
- rowdblclick
- rowenter
- rowleave
- select
- selectrow
- servererror
- set
- sort
- startedit
- statechange
- unlockcolumn
- update
- Methods
- add
- addChild
- addColumn
- addEvent
- addFilter
- addGroup
- autoSizeColumns
- clearData
- clearDirty
- clearFilter
- clearGroup
- clearSelection
- collapse
- collapseAll
- collapseGroup
- copy
- deSelectRow
- destroy
- disableSelection
- each
- editCell
- enableSelection
- expand
- expandAll
- expandGroup
- exportToCSV
- exportToExcel
- find
- findItem
- fire
- firstPage
- flashCell
- flashRow
- get
- getById
- getCell
- getChanges
- getColumn
- getColumnById
- getColumns
- getData
- getDataAsCSV
- getDataFiltered
- getDataView
- getFilter
- getHeaderCell
- getHeight
- getPage
- getPages
- getPageSize
- getRowById
- getSelection
- getSorter
- getSubTitle
- getTitle
- getTotal
- getViewTotal
- getWidth
- hide
- hideBar
- hideColumn
- hideLoadMask
- isDirty
- isLoading
- insert
- lastPage
- load
- lockColumn
- nextPage
- on
- once
- prevPage
- redo
- remove
- removeAll
- removeAt
- removeColumn
- removeRow
- removeRowById
- rightLockColumn
- save
- scroll
- scrollToRow
- search
- selectCell
- selectCellDown
- selectCellLeft
- selectCellRight
- selectCellUp
- selectColumn
- selectRow
- set
- setById
- setColumnComboData
- setColumns
- setColumnTitle
- setColumnWidth
- setData
- setHeight
- setPage
- setPageSize
- setParams
- setSelModel
- setSubTitle
- setTitle
- setTrackOver
- setUrl
- setWidth
- show
- showAt
- showBar
- showColumn
- showLoadMask
- sort
- stopEditor
- stopSelection
- toggleCollapse
- toggleExpand
- un
- undo
- undoAll
- unLockColumn
- update
- updateFilters
Data
FancyGrid supports many variants of data and approaches of working with it.
FancyGrid is oriented on using indexes(keys) of data.JSON data
Example: array of objects
data: [ {id: 1, name: 'Ted', surname: 'Smith'}, {id: 2, name: 'Ed', surname: 'Johnson'} ]
Indexes are:
id, name, surname
.In columns:
columns: [{ index: 'id', title: 'ID', type: 'number' },{ index: 'name', title: 'Name', type: 'string' },{ index: 'surname', title: 'SurName', type: 'string' }]
Array data
Example: array of arrays
data: [ [1, 'Ted', 'Smith'], [2, 'Ed', 'Johnson'] ]
Indexes are:
0, 1, 2
.In columns:
columns: [{ index: 0, title: 'ID', type: 'number' },{ index: 1, title: 'Name', type: 'string' },{ index: 2, title: 'SurName', type: 'string' }]
Array data with fields
Example: array of arrays, indexes set over fields
data: { fields: ['id', 'name', 'surname'] items: [ [1, 'Ted', 'Smith'], [2, 'Ed', 'Johnson'] ] }
Indexes are:
id, name, surname
.In columns:
columns: [{ index: 'id', title: 'ID', type: 'number' },{ index: 'name', title: 'Name', type: 'string' },{ index: 'surname', title: 'SurName', type: 'string' }]
Tree Data
In FancyGrid there is way to display nested data.
First you need to define column with typetree
columns: [{ index: 'name', title: 'Name', type: 'tree' },{ ... }]
Next you need nested data with 3 reversed words.
child
- for child elements.
expanded
- to notify that data node is expanded.
leaf
- for leaf nodes.
var data = [{ name: 'North America', type: 'Territory', expanded: true, child: [{ name: 'USA', type: 'Country', population: 325365189, child: [{ type: 'City', name: 'New York', population: 8175133, leaf: true },{ type: 'City', name: 'Washington', population: 681170, leaf: true }] },{ name: 'Canada', type: 'Country', population: 35151728, child: [{ type: 'City', name: 'Ottawa', population: 934243, leaf: true },{ type: 'City', name: 'Toronto', population: 2731571, leaf: true }] },{ name: 'Mexico', type: 'Country', population: 123675325, child: [{ type: 'City', population: 8918653, leaf: true, name: 'Mexico' }] }] },{ ... }]; new Fancygrid({ data: { items: data, fields: ['name', 'type', 'population'] }, ..., columns: [{ type: 'tree', title: 'Name', width: 200, index: 'name' },{ ...
For tree data it is recommended to set fields in data if nested childs have more params than parents.
new Fancygrid({ data: { items: data, fields: ['name', 'type', 'population'] },
Server data
load file
data: { proxy: { url: 'users.json' } }
Server response
{ "data": [ {"id": 1, "name": "Ted", "surname": "Smith"}, {"id": 2, "name": "Ed", "surname": "Johnson"} ] }
Check your server data, if you load JSON, it should be right, in other case rendering will not run.
Reader
In server response there is property that contains data values.
To change default name do this.data: { proxy: { url: 'users.json', reader: { root: 'items' } } }
Default reader root name is 'data'.
Server response
{ "items": [ {"id": 1, "name": "Ted", "surname": "Smith"}, {"id": 2, "name": "Ed", "surname": "Johnson"} ] }
Server sorting and paging.
If data is sorting or paging on server than grid sends special params on server.
Let us remind how enable server sorting and paging.
new FancyGrid({ ... data: { remoteSort: true, proxy: { url: 'ajax.php' } }, paging: true,
Setting pageSize
new FancyGrid({ ... data: { remoteSort: true, pageSize: 20, proxy: { url: 'ajax.php' } }, paging: true,
On server will be sent following params
Example: desc sorted by index
company
on second page with limit of 10 rows to show.sort:company dir:desc page:1 limit:10 start:10
Server response
Properties must be wrapped in quotes if you are using jQuery.
jQuery does not run success if there are not quotes.{ "data": [...], "success": true, "totalCount": 22 // needed for paging }
Server multi-sorting.
If data is multisorted than grid sends another params(comparing to usual sorting) on server.
new FancyGrid({ ... data: { remoteSort: true, proxy: { url: 'ajax.php' } }, multiSort: true,
On server it will be sent param
sorters
Example: Sorted grid by 2 columns.
Paramsorters
is Array.
Each item of array contains 3 params -key
- column index(key),dir
- sorting derection,type
- sorter: string|number.sorters: [{ key: 'surname', dir: 'ASC', type: 'string' },{ key: 'age', dir: 'DESC', type: 'number' }]
Server filtering.
To enable server filtering needs to set
remoteFilter: true
.
Also on server it sends filter param.
Filter param is array. Each item contains 3 property, they are:
operator
Filter operator.
value
Filter value.
property
Data index by which needs to filter.
Example of filter request params
filter: [{ operator: 'lt', value: 30, property: 'age' },{ operator: 'like', value: 'Adobe', property: 'company' }]
Operators can not be sent on server as
<, >, =
and others.
That is why there are alternative names for them.Communication with server.
In real application very often needed to do read, update, delete, insert data.
For that there is very popular solution - RESTful.
RESTful
data: { proxy: { type: 'rest', url: 'app.php/users' } },
For actions on server will be sent following methods.
read: 'GET' create: 'POST' update: 'PUT' destroy: 'DELETE'
Params that sent to server and get back from it.
Sample with sorting and paging.read: 'GET' url - app.php/users?sort=id&dir=asc&page=1&limit=10&start=10 Responce - {"success": true, "data": [...]}
create: 'POST' url - app.php/users Form Data - id:23 Responce - {"success":true,"message":"Created new User","data":{"id":23}}
In create action, param
id
is mainly for information purpose, server gives self id and returns it.
If server will not return id, than id that was sent for this row item will be in grid for sending update and delete actions to server.update: 'PUT' url - app.php/users Form Data - id:11 key:name value:John
destroy: 'DELETE' url - app.php/users Form Data - id:11
Self CRUD
In case you need self CRUD approach.data: { proxy: { methods: { create: 'POST', read: 'POST', update: 'POST', destroy: 'POST' }, api: { create: 'new.php', read: 'load.php', update: 'update.php', destroy: 'destroy_action.php' } } },
Instead of param
delete
, it is useddestroy
because in JavaScript worddelete
is reserved.Writer
Very often in apps it needs to send on server params as json.
data: { proxy: { type: 'rest', url: 'app.php/users', writer: { type: 'json', //allFields: true } } },
Set
writer.allFields
to true if requires to send all data item properties.Params that sent to server and get back from it.
Sample with sorting and paging.read: 'GET' url - app.php/users?sort=company&dir=asc&page=1&limit=10&start=10 Responce - {"success": true, data: [...]}
create: 'POST' url - app.php/users Request Payload - {"id":26} Responce - {"success":true,"message":"Created new User","data":{"id":27}}
In create action, param
id
is mainly for information purpose, server gives self id and returns it.
If server will not return id, than id that was sent for this row item will be in grid for sending update and delete actions to server.update: 'PUT' url - app.php/users Request Payload - {"id":2,"surname":"John"} Responce - {"success":true,"message": "Updated User 2"}
destroy: 'DELETE' url - app.php/users Request Payload - {"id":11} Responce - {"success":true,"message": "Destroyed User 11"}
AutoLoad - false
By default grid loads data on start.
If to disable this property than requires:
to load data over methodgrid.load();
.
Example
data: { proxy: { autoLoad: false, url: 'clients.php' } }, ... function loadData(){ grid.load(); }
Default
true
AutoSave - false
By default all changes will be sent on server.
If to disable this property than requires:
1 - to save changes over methodgrid.save();
.
2 - determine how changes should be saved - batched or on every change to send request.
To determine batching use propertydata.proxy.batch
by default it is true.
It will first send create commands than update and than delete.
3 - It would be good to config methods of sending for each command or to use RESTful.
When changes are batched FancyGrid try to send changes as JSON in Request PayLoad.
One change will be sent as object -{id: 5, age: 10}
Several changes will be sent as array[ {id: 5, age: 10}, {id: 7, name: 'John'} ]
4 - also it is possible to config properties that will be sent on server.
All properties or only changed.
By default it sends only changed properties, to send all fields usedata.proxy.writer.allFields
Example
data: { proxy: { autoSave: false, method: 'POST', url: 'app', writer: { type: 'json', allFields: true } } }, ... function saveChanges(){ grid.save(); }