Add button/function on grouping row ? It's possible ?

Add button/function on grouping row ? It's possible ?

pakypaky Posts: 106Questions: 0Answers: 0
edited November 2009 in General
Hi allan, any example for add button/func on row group ?

Replies

  • allanallan Posts: 63,692Questions: 1Answers: 10,500 Site admin
    Hi paky,

    I'm not entirely sure what you mean I'm afraid. What do you mean by a "row group"? The only add data function (off the top of my head) is this one: http://datatables.net/examples/api/add_row.html . It should be possible to integrate this with the row grouping example, just by adding the required data.

    Regards,
    Allan
  • pakypaky Posts: 106Questions: 0Answers: 0
    edited November 2009
    Can I put a return value in grouped row ? example ... sum of sub.rows ?

    thanks
  • allanallan Posts: 63,692Questions: 1Answers: 10,500 Site admin
    I think I see what you mean - and all that I think you need to do is add the data to the table as you would for a non-grouped example. Remember that the grouping is done by the sorting, so if I were to add a new row with 'Gecko' in the first column it would automatically be put into the 'Gecko' group.

    Regards,
    Allan
  • pakypaky Posts: 106Questions: 0Answers: 0
    Hi allan, sorry for my english and thanks for your patience... but I have not explained well !!

    not want to add rows ... in the grouped row with in past initialization I want add a sum of values.

    example:
    row_1 : X ; Tom ; 6
    row_2 : X ; Tim ; 17
    row_3 : X ; Jhon; 11

    row_4 : Y ; Paky ; 5

    after group rows I want on same group TR
    => X [34]
    Tom
    Tim
    Jhon
    => Y [ 5 ]
    Paky
  • allanallan Posts: 63,692Questions: 1Answers: 10,500 Site admin
    Hi Paky,

    Yes, no reason why that shouldn't be possible. When you are looping for the rows to look for the groups and then add the new TR/TD element for the group, why not just total up the information and add it in there (i.e. in fnDrawCallback).

    Allan
  • pakypaky Posts: 106Questions: 0Answers: 0
    ehm thanks allan for suggestion ... Can you give me a small generic example (fnDrawCallback)?
  • allanallan Posts: 63,692Questions: 1Answers: 10,500 Site admin
    Hi paky,

    I'm not inclined to just bash out code (since nobody learns that way, including me!), but hopefully I can point you in the right direction.

    In the fnDrawCallback function you have, you are looping over the TR elements in the table, checked on each loop to see if there is a new "group" required. It is trivial to modify this to add up the totals for each group - so I would suggest starting there (just getting the value from the DOM and adding it to a variable) and either alert() or console.log() that. Once that is going, you just need to enter your calculated value into the group row you created - again DOM methods will let you do this.

    Give it a go and see what happens :-)

    Allan
  • pakypaky Posts: 106Questions: 0Answers: 0
    edited November 2009
    Thanks allan, I locate column containing the data [b]var sGiorni= oSettings.aoData[ oSettings.aiDisplay[i] ]._aData[3];[/b]


    here my code:
    [code]
    var i=0;
    for ( var i=0 ; i
  • allanallan Posts: 63,692Questions: 1Answers: 10,500 Site admin
    Hi paky,

    Looks good. So the issue now is just colspan etc is it? The nCell variable always uses colspan, so perhap you can just modify that, and share 'iColspan' between the two TD elements? One other little thing, it's a good idea to create the ggSpan element outside of the if statement, since you are using it in the 'else'. I think it is okay here due to the loop - but it might be possible for the 'else' to happen before the variable is created in other code.

    Regards,
    Allan
  • pakypaky Posts: 106Questions: 0Answers: 0
    For iColspan vars I tried to reduce it ... (iColspan-2) it's not the solution !!! :( How can I share 'iColspan' between the two TD elements ?!

    If my iColspan = 4 , I would have two cells with colspan = 2

    thanks allan for all the advice !!! ;)
  • allanallan Posts: 63,692Questions: 1Answers: 10,500 Site admin
    Hi paky,

    I think you are along the right lines there - does something like this not work:

    [code]
    var nGroup = document.createElement( 'tr' );
    var nCell = document.createElement( 'td' );
    var ggSpan=document.createElement( 'td' );

    nCell.colSpan = iColspan-2;
    ggSpan.colSpan = 2;
    [/code]
    Regards,
    Allan
This discussion has been closed.