Add Created and Updated column
This commit is contained in:
@@ -7,6 +7,8 @@ import { PillarTable, TableState } from './table/Table'
|
|||||||
import { CellPrettyDate } from './table/cells/renderer/CellPrettyDate'
|
import { CellPrettyDate } from './table/cells/renderer/CellPrettyDate'
|
||||||
import { CellDefault } from './table/cells/renderer/CellDefault'
|
import { CellDefault } from './table/cells/renderer/CellDefault'
|
||||||
import { ColumnBase } from './table/columns/ColumnBase'
|
import { ColumnBase } from './table/columns/ColumnBase'
|
||||||
|
import { Created } from './table/columns/Created'
|
||||||
|
import { Updated } from './table/columns/Updated'
|
||||||
import { ColumnFactoryBase } from './table/columns/ColumnFactoryBase'
|
import { ColumnFactoryBase } from './table/columns/ColumnFactoryBase'
|
||||||
import { RowObjectsSourceBase } from './table/rows/RowObjectsSourceBase'
|
import { RowObjectsSourceBase } from './table/rows/RowObjectsSourceBase'
|
||||||
import { RowBase } from './table/rows/RowObjectBase'
|
import { RowBase } from './table/rows/RowObjectBase'
|
||||||
@@ -27,6 +29,8 @@ let table = {
|
|||||||
TableState,
|
TableState,
|
||||||
columns: {
|
columns: {
|
||||||
ColumnBase,
|
ColumnBase,
|
||||||
|
Created,
|
||||||
|
Updated,
|
||||||
ColumnFactoryBase,
|
ColumnFactoryBase,
|
||||||
},
|
},
|
||||||
cells: {
|
cells: {
|
||||||
|
@@ -0,0 +1,58 @@
|
|||||||
|
import { CellPrettyDate } from '../cells/renderer/CellPrettyDate'
|
||||||
|
import {ColumnBase} from './ColumnBase'
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Column showing the objects _created prettyfied
|
||||||
|
*/
|
||||||
|
|
||||||
|
export class Created extends ColumnBase{
|
||||||
|
constructor() {
|
||||||
|
super('Created', 'row-created');
|
||||||
|
this.includedByDefault = false;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
*
|
||||||
|
* @param {RowObject} rowObject
|
||||||
|
* @returns {String} Name of the Cell renderer component
|
||||||
|
*/
|
||||||
|
getCellRenderer(rowObject) {
|
||||||
|
return CellPrettyDate.options.name;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
*
|
||||||
|
* @param {RowObject} rowObject
|
||||||
|
* @returns {DateString}
|
||||||
|
*/
|
||||||
|
getRawCellValue(rowObject) {
|
||||||
|
return rowObject.underlyingObject['_created'];
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Cell tooltip
|
||||||
|
* @param {Any} rawCellValue
|
||||||
|
* @param {RowObject} rowObject
|
||||||
|
* @returns {String}
|
||||||
|
*/
|
||||||
|
getCellTitle(rawCellValue, rowObject) {
|
||||||
|
return rawCellValue;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Compare two rows to sort them. Can be overridden for more complex situations.
|
||||||
|
*
|
||||||
|
* @param {RowObject} rowObject1
|
||||||
|
* @param {RowObject} rowObject2
|
||||||
|
* @returns {Number} -1, 0, 1
|
||||||
|
*/
|
||||||
|
compareRows(rowObject1, rowObject2) {
|
||||||
|
let dueDateStr1 = this.getRawCellValue(rowObject1);
|
||||||
|
let dueDateStr2 = this.getRawCellValue(rowObject2);
|
||||||
|
if (dueDateStr1 === dueDateStr2) return 0;
|
||||||
|
if (dueDateStr1 && dueDateStr2) {
|
||||||
|
return new Date(dueDateStr1) < new Date(dueDateStr2) ? -1 : 1;
|
||||||
|
}
|
||||||
|
return dueDateStr1 ? -1 : 1;
|
||||||
|
}
|
||||||
|
}
|
@@ -0,0 +1,58 @@
|
|||||||
|
import { CellPrettyDate } from '../cells/renderer/CellPrettyDate'
|
||||||
|
import {ColumnBase} from './ColumnBase'
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Column showing the objects _updated prettyfied
|
||||||
|
*/
|
||||||
|
|
||||||
|
export class Updated extends ColumnBase{
|
||||||
|
constructor() {
|
||||||
|
super('Updated', 'row-updated');
|
||||||
|
this.includedByDefault = false;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
*
|
||||||
|
* @param {RowObject} rowObject
|
||||||
|
* @returns {String} Name of the Cell renderer component
|
||||||
|
*/
|
||||||
|
getCellRenderer(rowObject) {
|
||||||
|
return CellPrettyDate.options.name;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
*
|
||||||
|
* @param {RowObject} rowObject
|
||||||
|
* @returns {DateString}
|
||||||
|
*/
|
||||||
|
getRawCellValue(rowObject) {
|
||||||
|
return rowObject.underlyingObject['_updated'];
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Cell tooltip
|
||||||
|
* @param {Any} rawCellValue
|
||||||
|
* @param {RowObject} rowObject
|
||||||
|
* @returns {String}
|
||||||
|
*/
|
||||||
|
getCellTitle(rawCellValue, rowObject) {
|
||||||
|
return rawCellValue;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Compare two rows to sort them. Can be overridden for more complex situations.
|
||||||
|
*
|
||||||
|
* @param {RowObject} rowObject1
|
||||||
|
* @param {RowObject} rowObject2
|
||||||
|
* @returns {Number} -1, 0, 1
|
||||||
|
*/
|
||||||
|
compareRows(rowObject1, rowObject2) {
|
||||||
|
let dueDateStr1 = this.getRawCellValue(rowObject1);
|
||||||
|
let dueDateStr2 = this.getRawCellValue(rowObject2);
|
||||||
|
if (dueDateStr1 === dueDateStr2) return 0;
|
||||||
|
if (dueDateStr1 && dueDateStr2) {
|
||||||
|
return new Date(dueDateStr1) < new Date(dueDateStr2) ? -1 : 1;
|
||||||
|
}
|
||||||
|
return dueDateStr1 ? -1 : 1;
|
||||||
|
}
|
||||||
|
}
|
Reference in New Issue
Block a user