new Treebeard(opts)
The main Treebeard API with publicly available variables and methods
Parameters:
Name | Type | Description |
---|---|---|
opts |
Object | Options passed in |
Methods
(static) view(ctrl)
Mithril View. Documentation is here: (http://lhorie.github.io/mithril/mithril.html) Use m() for templating.
Parameters:
Name | Type | Description |
---|---|---|
ctrl |
Object | The entire Treebeard.controller object with its values and methods. Refer to as ctrl. |
calculateVisible(rangeIndex) → {Number}
Calculates total number of visible items to return a row height
Parameters:
Name | Type | Description |
---|---|---|
rangeIndex |
Number | The index to start refreshing range |
Returns:
total Number of items visible (not in showrange but total).
- Type
- Number
canMove(toItem, parentID) → {Boolean}
Checks if a move between items can be done based on logic of which contains the other
Parameters:
Name | Type | Description |
---|---|---|
toItem |
Object | Receiving item data constructed by _item |
parentID |
Object | Item to be moved as constructed by _item |
Returns:
Whether the move can be done or not
- Type
- Boolean
createItem(item, parentID) → {Object}
Adds an item to the list with proper tree and flat data and view updates
Parameters:
Name | Type | Description |
---|---|---|
item |
Object | the raw data of the item |
parentID |
Number | the unique id of the parent object the item should be added to |
Returns:
newItem the created item as constructed by _item with correct parent information.
- Type
- Object
deleteNode(parentID, itemID) → {Object}
Deletes item from tree and refreshes view
Parameters:
Name | Type | Description |
---|---|---|
parentID |
Number | Unique id of the parent |
itemID |
Number | Unique id of the item |
Returns:
A shallow copy of the item that was just deleted.
- Type
- Object
destroy()
Destroys Treebeard by emptying the DOM object and removing dropzone
Because DOM objects are removed their events are going to be cleaned up.
filter(e)
Runs filter functions and resets depending on whether there is a filter word
Parameters:
Name | Type | Description |
---|---|---|
e |
Event | Event object fired by the browser |
find(id) → {Number}
Finds the entire item object through the id only
Parameters:
Name | Type | Description |
---|---|---|
id |
Number | Unique id of the item acted on |
Returns:
_item The full item object constructed by _item.
- Type
- Number
flatten(value, visibleTop) → {Array}
Turns the tree structure into a flat index of nodes
Parameters:
Name | Type | Description |
---|---|---|
value |
Array | Array of hierarchical objects |
visibleTop |
Number | Passes through the beginning point so that refreshes can work, default is 0. |
Returns:
value Returns a flat version of the hierarchical objects in an array.
- Type
- Array
goToPage(value)
During pagination jumps to specific page
Parameters:
Name | Type | Description |
---|---|---|
value |
Number | the page number to jump to |
handleMultiselect(id, indexopt, eventopt)
Handles multiselect by adding items through shift or control key presses
Parameters:
Name | Type | Attributes | Description |
---|---|---|---|
id |
Number | The unique id of the item. | |
index |
Number |
<optional> |
The showRange index of the item |
event |
Event |
<optional> |
Click event on the item |
highlightMultiselect()
Adds highlight to the multiselected items using jquery.
init(el, isInit)
Initialization functions after the main body of the table is loaded
Parameters:
Name | Type | Description |
---|---|---|
el |
Object | The DOM element that config is run on |
isInit |
Boolean | Whether this function ran once after page load. |
initializeMove()
Instantiates draggable and droppable on DOM elements with options passed from self.options
isMultiselected(id) → {Boolean}
Check if item is part of the multiselected array
Parameters:
Name | Type | Description |
---|---|---|
id |
Number | The unique id of the item. |
Returns:
outcome Whether the item is part of multiselected
- Type
- Boolean
moveOff()
Removes move related instances by destroying draggable and droppable.
moveOn(parent)
Turns move on for all elements or elements within a parent container
Parameters:
Name | Type | Description |
---|---|---|
parent |
DOM element for parent |
onScroll()
Update view on scrolling the table
pageDown()
During pagination goes DOWN one page
pageUp()
During pagination goes UP one page
redraw()
Helper function to redraw if user makes changes to the item (like deleting through a hook)
refreshRange(begin)
Refreshes the view to start the the location where begin is the starting index
Parameters:
Name | Type | Description |
---|---|---|
begin |
Number | The index location of visible indexes to start at. |
removeMultiselected(id) → {Boolean}
Removes single item from the multiselected array
Parameters:
Name | Type | Description |
---|---|---|
id |
Number | The unique id of the item. |
Returns:
result Whether the item removal was successful
- Type
- Boolean
resetCounter(resetNum)
Helper function to reset unique id to a reset number or -1
Parameters:
Name | Type | Description |
---|---|---|
resetNum |
Number | Number to reset counter to |
resetKeyPress()
Resets keys that are hung up. Other window onblur event actions can be added in here.
returnIndex(id) → {Number}
Returns the index of an item in the flat row list (self.flatData)
Parameters:
Name | Type | Description |
---|---|---|
id |
Number | Unique id of the item acted on (usually item.id) . |
Returns:
i The index at which the item is found or undefined if nothing is found.
- Type
- Number
returnRangeIndex(id) → {Number}
Returns the index of an item in the showRange list (self.showRange)
Parameters:
Name | Type | Description |
---|---|---|
id |
Number | Unique id of the item acted on (usually item.id) . |
Returns:
i The index at which the item is found or undefined if nothing is found.
- Type
- Number
rowFilterResult(item) → {Boolean}
Returns whether a single row contains the filtered items, checking if columns can be filtered
Parameters:
Name | Type | Description |
---|---|---|
item |
Object | Item constructed with _item which the filtering is acting on. |
Returns:
titleResult Whether text is found within the item, default is false;
- Type
- Boolean
sortToggle(eventopt)
Toggles the sorting when clicked on sort icons.
Parameters:
Name | Type | Attributes | Description |
---|---|---|---|
event |
Event |
<optional> |
Toggle click event if this function is triggered by an event. |
toggleFolder(index, eventopt)
Toggles folder, refreshing the view or reloading in event of lazyload
Parameters:
Name | Type | Attributes | Description |
---|---|---|---|
index |
Number | The index of the item in the flatdata. | |
event |
Event |
<optional> |
Toggle click event if this function is triggered by an event. |
togglePaginate()
Changes view to pagination when clicked on the paginate button
toggleScroll()
Changes view to continous scroll when clicked on the scroll button
updateFolder(data, parent)
Updates content of the folder with new data or refreshes from lazyload
Parameters:
Name | Type | Description |
---|---|---|
data |
Array | New raw items, may be returned from ajax call |
parent |
Object | Item built with the _item constructor |
(inner) _applyDropzone()
Apply dropzone to grid with the optional hooks
(inner) _destroyDropzone()
Remove dropzone from grid
(inner) _loadData(data)
Loads the data pushed in to Treebeard and handles it to comply with treebeard data structure.
Parameters:
Name | Type | Description |
---|---|---|
data |
Array | String | Data sent in as an array of objects or a url in string form |