mirror of
https://github.com/techgaun/active-forks.git
synced 2024-11-16 09:08:32 +01:00
use custom render func for pushed_at closes #18
This commit is contained in:
parent
58a9329b31
commit
ebe187eba5
1 changed files with 11 additions and 3 deletions
12
js/main.js
12
js/main.js
|
@ -41,7 +41,6 @@ function updateDT( data ) {
|
|||
for ( let fork of data ) {
|
||||
fork.repoLink = `<a href="https://github.com/${fork.full_name}">Link</a>`
|
||||
fork.ownerName = fork.owner.login
|
||||
fork.pushed_at = moment(fork.pushed_at).fromNow()
|
||||
forks.push( fork )
|
||||
}
|
||||
const dataSet = forks.map( fork => window.columnNamesMap.map( colNM => fork[colNM[1]] ) )
|
||||
|
@ -68,9 +67,18 @@ function initDT() {
|
|||
const sortColumnIdx = window.columnNamesMap.map( pair => pair[0] ).indexOf( sortColName )
|
||||
|
||||
// Use first index for readable column name
|
||||
// we use moment's fromNow() if we are rendering for `pushed_at`; better solution welcome
|
||||
window.forkTable = $( '#forkTable' ).DataTable( {
|
||||
columns: window.columnNamesMap.map( colNM => {
|
||||
return {'title': colNM[0]}
|
||||
return {
|
||||
title: colNM[0],
|
||||
render: colNM[1] === 'pushed_at' ? (data, type, _row) => {
|
||||
if (type === 'display') {
|
||||
return moment(data).fromNow()
|
||||
}
|
||||
return data
|
||||
} : null
|
||||
}
|
||||
}),
|
||||
'order': [[sortColumnIdx, 'desc']],
|
||||
} )
|
||||
|
|
Loading…
Reference in a new issue