From ebe187eba55d118527c0feea492133c113570ada Mon Sep 17 00:00:00 2001 From: techgaun Date: Sun, 18 Nov 2018 01:37:47 -0600 Subject: [PATCH] use custom render func for pushed_at closes #18 --- js/main.js | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-) diff --git a/js/main.js b/js/main.js index b99e771..d273ad9 100644 --- a/js/main.js +++ b/js/main.js @@ -41,7 +41,6 @@ function updateDT( data ) { for ( let fork of data ) { fork.repoLink = `Link` 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,10 +67,19 @@ 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']], } ) }