|
166 | 166 | var table = new Tabulator("#report", {
|
167 | 167 | ajaxURL:baseUrl,
|
168 | 168 | layout:"fitColumns",
|
| 169 | + downloadDataFormatter:function(data){ |
| 170 | + //data - active table data array |
| 171 | + data.forEach(function(row){ |
| 172 | + |
| 173 | + var time = row.time; |
| 174 | + var duration = row.totalDuration; |
| 175 | + if (group1 != '' || group2 != '' || group3 != ''){ |
| 176 | + row.ended = '*'; |
| 177 | + } else { |
| 178 | + var ended = moment(time, 'YYYY-MM-DD hh:mm:ss').add(duration,"seconds").format('YYYY-MM-DD HH:mm'); |
| 179 | + row.ended = ended; |
| 180 | + |
| 181 | + } |
| 182 | + |
| 183 | + var s = Math.floor( (duration) % 60 ); |
| 184 | + var m = Math.floor( (duration/60) % 60 ); |
| 185 | + var h = Math.floor( (duration/(60*60))); |
| 186 | + |
| 187 | + row.totalDuration = pad(h,2) + ':' + pad(m,2) + ':' + pad(s,2); |
| 188 | + |
| 189 | + if (row.project == null){ |
| 190 | + row.project = ''; |
| 191 | + } |
| 192 | + if (row.client == null){ |
| 193 | + row.client = ''; |
| 194 | + } |
| 195 | + |
| 196 | + }); |
| 197 | + |
| 198 | + return data; |
| 199 | + }, |
169 | 200 | columns:[
|
170 | 201 | //{title:"Id", field:"id", width:100}, //column has a fixed width of 100px;
|
171 | 202 | {title:"#", field:"", formatter:"rownum"},
|
|
187 | 218 | return pad(h,2) + ':' + pad(m,2) + ':' + pad(s,2);
|
188 | 219 |
|
189 | 220 | },bottomCalc:"sum", bottomCalcParams:{
|
190 |
| - precision:1, |
191 |
| - },bottomCalcFormatter:function(cell, formatterParams, onRendered){ |
192 |
| - //cell - the cell component |
193 |
| - //formatterParams - parameters set for the column |
194 |
| - //onRendered - function to call when the formatter has been rendered |
195 |
| - var duration = cell.getValue(); |
196 |
| - var s = Math.floor( (duration) % 60 ); |
197 |
| - var m = Math.floor( (duration/60) % 60 ); |
198 |
| - var h = Math.floor( (duration/(60*60))); |
| 221 | + precision:1, |
| 222 | + },bottomCalcFormatter:function(cell, formatterParams, onRendered){ |
| 223 | + //cell - the cell component |
| 224 | + //formatterParams - parameters set for the column |
| 225 | + //onRendered - function to call when the formatter has been rendered |
| 226 | + var duration = cell.getValue(); |
| 227 | + var s = Math.floor( (duration) % 60 ); |
| 228 | + var m = Math.floor( (duration/60) % 60 ); |
| 229 | + var h = Math.floor( (duration/(60*60))); |
199 | 230 |
|
200 |
| - return pad(h,2) + ':' + pad(m,2) + ':' + pad(s,2); |
| 231 | + return pad(h,2) + ':' + pad(m,2) + ':' + pad(s,2); |
201 | 232 |
|
202 |
| - }}, //column will be allocated 1/5 of the remaining space |
| 233 | + }}, //column will be allocated 1/5 of the remaining space |
| 234 | + {title:"Ended", field:"ended",visible:false, formatter:function(cell, formatterParams, onRendered){ |
| 235 | + //cell - the cell component |
| 236 | + //formatterParams - parameters set for the column |
| 237 | + //onRendered - function to call when the formatter has been rendered |
| 238 | + if (group1 != '' || group2 != '' || group3 != ''){ |
| 239 | + return '*'; |
| 240 | + } |
| 241 | + var time = cell.getRow().getData().time; |
| 242 | + var duration = cell.getRow().getData().totalDuration; |
| 243 | + var ended = moment(time, 'YYYY-MM-DD hh:mm:ss').add(duration,"seconds").format('YYYY-MM-DD HH:mm'); |
| 244 | + return ended; |
| 245 | + |
| 246 | + }}, |
203 | 247 | ],
|
204 | 248 | ajaxResponse:function(url, params, response){
|
205 | 249 |
|
206 | 250 | return response.items; //return the tableData property of a response json object
|
207 | 251 | },
|
208 | 252 | });
|
209 | 253 | $("#download-csv").off().click(function(){
|
| 254 | + table.showColumn("ended"); |
210 | 255 | table.download("csv", "data.csv");
|
| 256 | + table.hideColumn("ended"); |
211 | 257 | return false;
|
212 | 258 | });
|
213 | 259 | $("#download-json").off().click(function(){
|
| 260 | + table.showColumn("ended"); |
214 | 261 | table.download("json", "data.json");
|
| 262 | + table.hideColumn("ended"); |
215 | 263 | return false;
|
216 | 264 | });
|
217 | 265 | }
|
|
0 commit comments