mirror of
https://github.com/crater-invoice/crater.git
synced 2025-10-30 05:01:10 -04:00
init crater
This commit is contained in:
61
resources/assets/js/components/base/base-table/classes/Row.js
Executable file
61
resources/assets/js/components/base/base-table/classes/Row.js
Executable file
@ -0,0 +1,61 @@
|
||||
import moment from 'moment'
|
||||
import { get } from '../helpers'
|
||||
|
||||
export default class Row {
|
||||
constructor (data, columns) {
|
||||
this.data = data
|
||||
this.columns = columns
|
||||
}
|
||||
|
||||
getValue (columnName) {
|
||||
return get(this.data, columnName)
|
||||
}
|
||||
|
||||
getColumn (columnName) {
|
||||
return this.columns.find(column => (column.show === columnName || column.sortAs === columnName))
|
||||
}
|
||||
|
||||
getFilterableValue (columnName) {
|
||||
const value = this.getValue(columnName)
|
||||
|
||||
if (!value) {
|
||||
return ''
|
||||
}
|
||||
|
||||
return value.toString().toLowerCase()
|
||||
}
|
||||
|
||||
getSortableValue (columnName) {
|
||||
const dataType = this.getColumn(columnName).dataType
|
||||
|
||||
let value = this.getValue(columnName)
|
||||
|
||||
if (value === undefined || value === null) {
|
||||
return ''
|
||||
}
|
||||
|
||||
if (value instanceof String) {
|
||||
value = value.toLowerCase()
|
||||
}
|
||||
|
||||
if (dataType.startsWith('date')) {
|
||||
const format = dataType.replace('date:', '')
|
||||
|
||||
return moment(value, format).format('YYYYMMDDHHmmss')
|
||||
}
|
||||
|
||||
if (dataType === 'numeric') {
|
||||
return value
|
||||
}
|
||||
|
||||
return value.toString()
|
||||
}
|
||||
|
||||
passesFilter (filter) {
|
||||
return this.columns
|
||||
.filter(column => column.isFilterable())
|
||||
.map(column => this.getFilterableValue(column.getFilterFieldName()))
|
||||
.filter(filterableValue => filterableValue.indexOf(filter.toLowerCase()) >= 0)
|
||||
.length
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user