MCPcopy Create free account
hub / github.com/breck7/scroll / createColumnDefs

Method createColumnDefs

external/.tableSearch.js:118–138  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

116 }
117
118 createColumnDefs() {
119 const columnDefs = []
120 this.dateColumns.forEach((newName, index) => {
121 columnDefs.push({
122 targets: index,
123 render: (data, type) => {
124 if (type === "display") {
125 // Parse the date and return relative time
126 const timestamp = /^\d+$/.test(data) ? (String(data).length < 9 ? parseInt(data) * 1000 : parseInt(data)) : data
127 const date = dayjs(timestamp)
128 if (date.isValid()) {
129 return `<span title="${date.toLocaleString()}">${date.fromNow()}</span>`
130 }
131 }
132 // Return original data for sorting/filtering
133 return data
134 }
135 })
136 })
137 return columnDefs
138 }
139
140 bindToHashChange() {
141 window.addEventListener("hashchange", () => {

Callers 1

createDatatableMethod · 0.95

Calls 2

forEachMethod · 0.80
isValidMethod · 0.45

Tested by

no test coverage detected