Skip to content

Instantly share code, notes, and snippets.

@niks551
Created August 13, 2013 04:30
Show Gist options
  • Save niks551/6217915 to your computer and use it in GitHub Desktop.
Save niks551/6217915 to your computer and use it in GitHub Desktop.
window.camp_dataTable = $('#temp_data')
.dataTable(
{
bProcessing : true,
sPaginationType : "full_numbers",
aLengthMenu : [
[
10,
20,
50,
100,
500,
-1 ],
[
10,
20,
50,
100,
500,
"All" ] ],
bStateSave : true,
sCookiePrefix : "campaign_",
iCookieDuration : 365,
aaSorting : [ [ 1,
"asc" ] ],
aoColumns : [
null,
{
"sSortDataType" : "dom-date",
"sType" : "date",
"bSearchable" : false
},
null,
{
"sSortDataType" : "dom-percent",
"sType" : "numeric",
"bSearchable" : false
},
{
"sSortDataType" : "dom-percent",
"sType" : "numeric",
"bSearchable" : false
},
{
"sSortDataType" : "dom-percent",
"sType" : "numeric",
"bSearchable" : false
},
{
"sSortDataType" : "dom-percent",
"sType" : "numeric",
"bSearchable" : false
},
{
"sSortDataType" : "dom-percent",
"sType" : "numeric",
"bSearchable" : false
},
{
"sSortDataType" : "dom-percent",
"sType" : "numeric",
"bSearchable" : false
},
{
"sSortDataType" : "dom-percent",
"sType" : "numeric",
"bSearchable" : false
},
{
"sSortDataType" : "dom-percent",
"sType" : "numeric",
"bSearchable" : false
},
{
"sSortDataType" : "dom-percent",
"sType" : "numeric",
"bSearchable" : false
},
{
"sSortDataType" : "dom-percent",
"sType" : "numeric",
"bSearchable" : false
},
{
"sSortDataType" : "dom-percent",
"sType" : "numeric",
"bSearchable" : false
},
{
"sSortDataType" : "dom-percent",
"sType" : "numeric",
"bSearchable" : false
},
{
"sSortDataType" : "dom-percent",
"sType" : "numeric",
"bSearchable" : false
} ],
fnFooterCallback: function ( nRow, aaData, iStart, iEnd, aiDisplay ) {
/*
* Calculate the total attributes share for all merchants in this table (ie inc. outside
* the pagination)
*/
var iTotalGoals = 0;
var iTotalEmails=0;
var iTotalDeliveries=0;
var iTotalAccepts=0;
var iTotalVisitors=0;
var iTotalCarts=0;
var iTotalRevenue=0;
var iTotalLost=0;
var iTotalOrders=0;
var iTotalUpLift=0;
//for averages
var iTotalCR=0;
var iTotalActiveCampaigns=0;
var iTotalAOV=0;
for ( var i=0 ; i<aaData.length ; i++ )
{
iTotalDeliveries +=parseInt(aaData[i][3]*1);
iTotalAccepts +=parseInt(aaData[i][4]*1);
iTotalVisitors +=parseInt(aaData[i][5]*1);
iTotalGoals += parseInt(aaData[i][7]*1);
iTotalEmails +=parseInt(aaData[i][8]*1);
iTotalCarts +=parseInt(aaData[i][9]*1);
iTotalLost +=parseInt(aaData[i][10]*1);
iTotalRevenue +=parseInt(aaData[i][11]*1);
iTotalOrders +=parseInt(aaData[i][12]*1);
iTotalUpLift +=parseInt(aaData[i][15]*1);
iTotalCR+=parseFloat(aaData[i][13]*1);
iTotalAOV+=parseFloat(aaData[i][14]*1);
iTotalActiveCampaigns+=parseInt(aaData[i][6]*1);
}
/* Calculate the page attributes for merchants on this page */
var iPageDeliveries=0;
var iPageAccepts=0;
var iPageGoals = 0;
var iPageVisitors=0;
var iPageEmails=0;
var iPageCarts=0;
var iPageRevenue=0;
var iPageLost=0;
var iPageOrders=0;
var iPageUpLift=0;
var iPageCR=0;
var iPageActiveCampaigns=0;
var iPageAOV=0;
for ( var i=iStart ; i<iEnd ; i++ )
{
iPageDeliveries += parseInt(aaData[ aiDisplay[i] ][3]*1);
iPageAccepts+= parseInt(aaData[ aiDisplay[i] ][4]*1);
iPageVisitors+= parseInt(aaData[ aiDisplay[i] ][5]*1);
iPageGoals += parseInt(aaData[ aiDisplay[i] ][7]*1);
iPageEmails += parseInt(aaData[ aiDisplay[i] ][8]*1);
iPageCarts += parseInt(aaData[ aiDisplay[i] ][9]*1);
iPageRevenue += parseInt(aaData[ aiDisplay[i] ][11]*1);
iPageLost += parseInt(aaData[ aiDisplay[i] ][10]*1);
iPageOrders += parseInt(aaData[ aiDisplay[i] ][12]*1);
iPageUpLift += parseInt(aaData[ aiDisplay[i] ][15]*1);
iPageCR += parseFloat(aaData[ aiDisplay[i] ][13]*1);
iPageActiveCampaigns += parseInt(aaData[ aiDisplay[i] ][6]*1);
iPageAOV += parseFloat(aaData[ aiDisplay[i] ][14]*1);
}
/* Modify the footer row to match what we want */
var nCells = nRow.getElementsByTagName('th');
nCells[3].innerHTML = iPageDeliveries +
' of ('+ iTotalDeliveries +')';
nCells[4].innerHTML = iPageAccepts +
' of ('+ iTotalAccepts +')';
nCells[5].innerHTML = iPageVisitors +
' of ('+ iPageVisitors +')';
nCells[7].innerHTML = iPageGoals +
' of ('+ iTotalGoals +')';
nCells[8].innerHTML = iPageEmails +
' of ('+ iTotalEmails +')';
nCells[9].innerHTML = iPageCarts +
' of ('+ iTotalCarts +')';
nCells[10].innerHTML = iPageLost +
' of ('+ iTotalLost +')';
nCells[11].innerHTML = iPageRevenue +
' of ('+ iTotalRevenue +')';
nCells[12].innerHTML = iPageOrders +
' of ('+ iTotalOrders +')';
nCells[15].innerHTML = iPageUpLift +
' of ('+ iTotalUpLift +')';
var pageCRavg=parseFloat((iPageCR)/(iEnd-iStart)).toFixed(2);
var totalCRavg=parseFloat((iTotalCR)/(aaData.length)).toFixed(2);
nCells[13].innerHTML = pageCRavg +
' of ('+ totalCRavg +')';
var pageActiveCampaignsavg=parseInt((iPageActiveCampaigns)/(iEnd-iStart));
var TotalActiveCampaignsavg=parseInt((iTotalActiveCampaigns)/(aaData.length));
nCells[6].innerHTML = pageActiveCampaignsavg +
' of ('+ TotalActiveCampaignsavg +')';
var pageAOVavg=parseFloat((iPageAOV)/(iEnd-iStart)).toFixed(2);
var totalAOVavg=parseFloat((iTotalAOV)/(aaData.length)).toFixed(2);
nCells[14].innerHTML = pageAOVavg +
' of ('+ totalAOVavg +')';
}
});
new FixedHeader(window.camp_dataTable);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment