How to use jGreed
You need a jQuery object that will be the grid container, a column model, a dataset and several options - like this:
$.jgreed($("#greedContainer"),columnModel,dataSet,options);
The Column Model
The Column Model is an array of objects describing each column of the grid. Each object consists of the following:
- id [string] - an identification key for the column, to be used in the Data Set
- label [string/html] - the title on the column header;
- dataType [string/html] - one of "string","date","datejs" (requires the DateJS plugin to be loaded) or "number" (as of v0.1);
- sortable [boolean] - determines if the column has the sort button on the header;
- autoFilter [boolean] - determines if the column has the autoFilter button on the header;
- editable [boolean] - determines if the column can be edited when the row is selected for edit;
- width [string/%] - percent of the total table width (not used as of v0.1);
- hidden [boolean] - whether this column is shown in the grid;
- aggFunction [string] - one of "min","max","avg",or "sum"
The Data Set
The Data Set is an array of objects, each of which contains the column id as key and the value; each object must contain the index key defined in the grid Options
The Options
The grid Options represent an object with some of the following parameters:
- index [string] - the column id that will be used to identify each row
- addRows [boolean] - whether the grid allows new rows to be added
- editRows [boolean] - whether the grid allows every row to be edited
- striped [boolean] - whether the grid colors odd rows differently
- totalRow [boolean] - whether the grid should add a Total (Aggregate) Row at the end, calculated by each Column's aggFunction
- onLoad [function ()] - the callback function to be executed when the grid has finished loading
- deleteFunction [function(rowid)] - the callback function to be executed when a row is deleted from the grid
- saveFunction [function(rowObject,callbackFunction(newdata))] - the callback function to be executed when an edited or new row is saved; it gives the user an object just like those in the Data Set, as well as a function to be used in order to reload the grid with the new Data Set (after save)
- onFilter [function(filterBy,filterStatus,filterItems)] - the callback function to be executed when a Filter is in effect; filterStatus represents one of 1 (filter has been requested, filter panel is displayed) or 2 (filter has been submitted, filter is in effect); filterItems is an array with each distinct [value] in the filterBy column and their respective filter [status]
- onFilterClear [function(rowObject)] - the callback function to be executed when a Filter is removed