mutable.js revision c25f05e8aa5c555f79e3e8fd68fb2d2850b0d57b
0N/AAdds mutation convenience methods to `Y.DataTable` (or other built class). 0N/AColumn mutation methods are paired with new custom events: 0N/ARow mutation events are bubbled from the DataTable's `data` ModelList through 0N/Athe DataTable instance. 0N/A@module datatable-mutable 0N/A@class DataTable.Mutable 0N/A Adds the column configuration to the DataTable's `columns` configuration. 0N/A If the `index` parameter is supplied, it is injected at that index. If the 0N/A table has nested headers, inject a subcolumn by passing an array of indexes 0N/A to identify the new column's final location. 0N/A The `index` parameter is required if adding a nested column. 0N/A This method is a convienience method for fetching the DataTable's `columns` 0N/A attribute, updating it, and calling 0N/A `table.set('columns', _updatedColumnsDefs_)` 0N/A // Becomes last column 0N/A table.addColumn('name'); 0N/A // Inserted after the current second column, moving the current third column 0N/A table.addColumn({ key: 'price', formatter: currencyFormatter }, 2 ); 0N/A // Insert a new column in a set of headers three rows deep. The index array 0N/A // [ 2, -- in the third column's children 0N/A // 1, -- in the second child's children 0N/A // 3 ] -- as the fourth child column 0N/A table.addColumn({ key: 'age', sortable: true }, [ 2, 1, 3 ]); 0N/A @param {Object|String} config The new column configuration object 0N/A @param {Number|Number[]} [index] the insertion index 0N/A Updates an existing column definition. Fires the `modifyColumn` event. 0N/A // Add a formatter to the existing 'price' column definition 0N/A table.modifyColumn('price', { formatter: currencyFormatter }); 0N/A // Change the label on a header cell in a set of nested headers three rows 0N/A // deep. The index array translates to 0N/A // [ 2, -- in the third column's children 0N/A // 1, -- the second child 0N/A // 3 ] -- the fourth child column 0N/A table.modifyColumn([2, 1, 3], { label: 'Experience' }); 0N/A @method modifyColumn 0N/A @param {String|Number|Number[]|Object} name The column key, name, index, or 0N/A current configuration object 0N/A @param {Object} config The new column configuration properties 0N/A Moves an existing column to a new location. Fires the `moveColumn` event. 0N/A The destination index can be a number or array of numbers to place a column 0N/A header in a nested header row. 0N/A @param {String|Number|Number[]|Object} name The column key, name, index, or 0N/A current configuration object 0N/A @param {Number|Number[]} index The destination index of the column 0N/A Removes an existing column. Fires the `removeColumn` event. 0N/A @method removeColumn 0N/A @param {String|Number|Number[]|Object} name The column key, name, index, or 0N/A current configuration object 0N/A Adds a new record to the DataTable's `data` ModelList. Record data can be 0N/A an object of field values or an instance of the DataTable's configured 0N/A This relays all parameters to the `data` ModelList's `add` method. 0N/A @param {Object} data The data or Model instance for the new record 0N/A Removes a record from the DataTable's `data` ModelList. The record can be 0N/A provided explicitly or targeted by it's `id` (see ModelList's `getById` 0N/A method), `clientId`, or index in the ModelList. 0N/A After locating the target Model, this relays the Model and all other passed 0N/A arguments to the `data` ModelList's `remove` method. 0N/A @param {Object|String|Number} id The Model instance or identifier 0N/A // TODO: support removing via DOM element. This should be relayed to View 0N/A Updates an existing record in the DataTable's `data` ModelList. The record 0N/A can be provided explicitly or targeted by it's `id` (see ModelList's 0N/A `getById` method), `clientId`, or index in the ModelList. 0N/A After locating the target Model, this relays the all other passed 0N/A arguments to the Model's `setAttrs` method. 0N/A @param {Object|String|Number} id The Model instance or identifier 617N/A // -------------------------------------------------------------------------- 617N/A // Protected properties and methods 0N/A // -------------------------------------------------------------------------- 617N/A Default function for the `addColumn` event. 617N/A Inserts the specified column at the provided index. 617N/A @method _defAddColumnFn 0N/A @param {EventFacade} e The `addColumn` event 0N/A @param {Object} e.column The new column definition object 0N/A @param {Number|Number[]} e.index The array index to insert the new column 0N/A }
else { Y.
log(
'addColumn index not findable',
'warn',
'datatable');
0N/A Default function for the `modifyColumn` event. 617N/A Mixes the new column properties into the specified column definition. 617N/A @method _defModifyColumnFn 0N/A @param {EventFacade} e The `modifyColumn` event 617N/A @param {Object|String|Number|Number[]} e.column The column definition object or identifier 617N/A @param {Object} e.newColumnDef The properties to assign to the column 0N/A }
else { Y.
log(
'Could not locate column index to modify column',
'warn',
'datatable');
0N/A Default function for the `moveColumn` event. 0N/A Removes the specified column from its current location and inserts it at the 0N/A specified array index (may be an array of indexes for nested headers). 0N/A @method _defMoveColumnFn 0N/A @param {EventFacade} e The `moveColumn` event 0N/A @param {Object|String|Number|Number[]} e.column The column definition object or identifier 0N/A @param {Object} e.index The destination index to move to 0N/A }
else { Y.
log(
'Column [' + e.
column +
'] could not be moved. Destination index invalid for moveColumn',
'warn',
'datatable');
0N/A }
else { Y.
log(
'Column [' + e.
column +
'] not found for moveColumn',
'warn',
'datatable');
0N/A Default function for the `removeColumn` event. 0N/A Splices the specified column from its containing columns array. 0N/A @method _defRemoveColumnFn 0N/A @param {EventFacade} e The `removeColumn` event 0N/A @param {Object|String|Number|Number[]} e.column The column definition object or identifier 0N/A }
else { Y.
log(
'Could not locate column [' + e.
column +
'] for removeColumn',
'warn',
'datatable');
0N/A Publishes the events used by the mutation methods: 0N/AAdds an array of new records to the DataTable's `data` ModelList. Record data 0N/Acan be an array of objects containing field values or an array of instance of 0N/Athe DataTable's configured `recordType` class. 0N/AThis relays all parameters to the `data` ModelList's `add` method. 0N/ATechnically, this is an alias to `addRow`, but please use the appropriately 0N/Anamed method for readability. 0N/A@param {Object[]} data The data or Model instances to add 0N/A// Add feature APIs to public Y.DataTable class 0N/AFired by the `addColumn` method. 0N/A@preventable _defAddColumnFn 0N/A@param {Object} column The new column definition object 0N/A@param {Number|Number[]} index The array index to insert the new column 0N/AFired by the `removeColumn` method. 0N/A@preventable _defRemoveColumnFn 0N/A@param {Object|String|Number|Number[]} column The column definition object or identifier 0N/AFired by the `modifyColumn` method. 0N/A@preventable _defModifyColumnFn 0N/A@param {Object|String|Number|Number[]} column The column definition object or identifier 0N/A@param {Object} newColumnDef The properties to assign to the column 0N/AFired by the `moveColumn` method. 0N/A@preventable _defMoveColumnFn 0N/A@param {Object|String|Number|Number[]} column The column definition object or identifier 0N/A@param {Object} index The destination index to move to