Footer sum: visualizing only the coloumn i want to visualize

Footer sum: visualizing only the coloumn i want to visualize

sinansinan Posts: 7Questions: 0Answers: 0
edited August 2011 in General
Hi all, i have a problem with visualizing footer sum of cells that are above the sum in my table. In particular I want that the sum in the footer follow the coloumn not only when i move that coloumn, but also when i move the coloumn and after that i use the search function. Now what happens is that if i move the coloum also the footer sum moves, but if then i try to use the search, that sum is not displayed.


Other things is that i tryed also to display the sum of the coloumn,that i only want to display, using sName property of a coloumn.For exemple if i want to display some coloumns sums i have tryed to set the sName of that coloumn to "true" otherwise "false". But when i try to get back the values of sName of my coloumns i'm not sure if using dataTableOpt.fnSettings().aoColumns[v].sName is oki or works.

Anyone know how i can solve my problems??

Thank you in advance

Replies

  • allanallan Posts: 63,531Questions: 1Answers: 10,475 Site admin
    Can you post a link to your example please - I don't quite understand the issue I'm afraid. Why wouldn't the sum be displayed when you have a filter applied, but it is when you don't?

    Allan
  • sinansinan Posts: 7Questions: 0Answers: 0
    edited August 2011
    My Code is inside a googleGadget: i inizialize tha aoColumns like this:

    dataTableOpt.aoColumns=new Array();
    for(var j=0;j
  • allanallan Posts: 63,531Questions: 1Answers: 10,475 Site admin
    You want to be using http://datatables.net/ref#fnFooterCallback (like in this example: http://datatables.net/release-datatables/examples/advanced_init/footer_callback.html ) to update the footer on each draw.

    Allan
  • sinansinan Posts: 7Questions: 0Answers: 0
    edited August 2011
    So in that code, how we know which of the coloumn footers is update?Because i have understand that in the example above there are 2 different sum: the total sum and the sum of the rows visualized, but i don't have understand in the section /* Modify the footer row to match what we want */,where you refer to the footer of the coloumn 4. In that line maybe?

    var nCells = nRow.getElementsByTagName('th');

    In my table i have for example the column 2,4,5 numeric and i only want the total of the coloumn 2,4 in the footer. How i can discriminate?Only with the coloumn position?I think no because if i let the user to move the coloumns the code try to do the sum of a coloumn which contain a string i supposed.


    Thank you

    /* Calculate the market share for browsers on this page */
    var iPageMarket = 0;
    for ( var i=iStart ; i
  • allanallan Posts: 63,531Questions: 1Answers: 10,475 Site admin
    One way would be to have a class on the TH cells for the columns you want to have a sum for, then you can easily find out the index of the column and use that to 1. calculate the column totals and then 2. write it into the footer cells.

    Allan
  • sinansinan Posts: 7Questions: 0Answers: 0
    Hi Allan sorry, can u tell me if there are error in this code please?How do you get the sName parameter value of a coloumn? When i inizialize the table i tryed to set that sName parameter of my table in this mode you can see below, so lwhen i try later to visualize the sum in the footer i can get the Sname parameter to test if i have to visualize the sum or not for a current coloumn:

    Setting the sName parameter:

    if(indicepresente==true){obj.sName="true";} // if the indexes matches
    else {obj.sName="false";}
    dataTableOpt.aoColumns.push(obj);

    It's oki?

    Then i tried to get the sName parameter value of coloumns in this mode:

    for(var i=0;i
  • sinansinan Posts: 7Questions: 0Answers: 0
    Hi all, i still didn't found the solution of my problem.

    In that example that Allan showed me
    http://datatables.net/release-datatables/examples/advanced_init/footer_callback.html

    the column of the table are fixed (the user can't reoder the coloumn). What happens if is allowed the column reorder by user? I think that calculating the sum of the coloumn 4 (fixed) give errors right?

    So If it is possible i want that the user can arbitrally reorder the coloumn, without losing the sum on the footer. How i can do that?
  • allanallan Posts: 63,531Questions: 1Answers: 10,475 Site admin
    If you can reorder the columns (using ColReorder?) you need to know which column you are going to sum - this could be done with sName for example ( http://datatables.net/ref#sName ) - you would need to loop over the aoColumns array (from fnSettings()) and find the column with the sName that you want, then use that index to sum it.

    Allan
  • sinansinan Posts: 7Questions: 0Answers: 0
    edited September 2011
    Yes i use ColReorder. Now i have set the property sName of each column in aoColumns definition to
    "false" or "true" depending from other parameters. Then i check the sName property with this code:

    //loop the aoColumns array
    for (i = 0; i < oTable.fnSettings().aoColumns.length; i++) {
    if (oTable.fnSettings().aoColumns[i].sName == "true"){
    var visibleIndex=this.fnSettings().oApi._fnColumnIndexToVisible(this.fnSettings(),i);
    if(visibleIndex){

    if(sums[i]){
    $('#example tfoot th:eq('+visibleIndex+')').html(''+sums[i]+'');
    }
    }


    }

    }

    Now there is a problem that is, when i move a column and then i use the "Search" option for filtering some row the footer sum disappear. What function is call andwhat happens when in dataTable is used the "search" option?
This discussion has been closed.