Jump to content


Add a extra row for calculating total for few tables

row total

  • Please log in to reply
4 replies to this topic

#1 MD Rahat Islam Khan

MD Rahat Islam Khan

    Member

  • Members
  • PipPip
  • 13 posts

Posted 05 March 2014 - 03:57 AM

The more i am using grocery crud i am loving it more and more anyways the problem is i want to add an extra row to the end for few tables to calculate the total of one/two columns.  i don't want to modify the template(flexid grid) because i want to get the total for few tables.Is it possible.please help me fixing this



#2 Amit Shah

Amit Shah

    grocery CRUD Master

  • Advanced Member
  • PipPipPip
  • 1,192 posts
  • LocationMumbai, India

Posted 05 March 2014 - 01:34 PM

Hello brother...

 

In the way u want to achieve yes there is a need for u to hack in the GC library and patch it. The same patch as required is provided in here....

 

post the application of the patch .. u need to create a js file (custom.js .. or anything that suites u) and using set_js ... add the same (as refered to in the example in the link shared above)..

 

//This is conjunction to the customers managements example in the GC library itself ...

function do_the_sum(){
	$('#flex1 tr').last().after('<tr><td colspan=7><h3 style="color:red">Sub Total</h3></td><td><strong>' + sumOfColumns($('#flex1 tbody'), 8) + '</strong></td><td>&nbsp;</td></tr>');
}

function sumOfColumns(table, columnIndex) {
    var tot = 0;
    table.find("tr").children("td:nth-child(" + columnIndex + ")")
    .each(function() {
        $this = $(this);
        if (!$this.hasClass("sum") && $this.text() != "") {
        	if($.isNumeric($this.text()) 
            	tot += parseInt($this.text());
        }
    });
    return tot;
}

the above function will ensure u will add a row dynamically @the end of the table (formatting is in your hand .. u need to apply it the way u want). Rest .. the second function will parse up all the values of the given field number and sum up and return you the value (now here u can apply currency formatting / number formatting whatever suites you).

 

and at the last in your grud after the set_js function call...

$crud->set_js('assets/scripts/callback.js'); // here i add / include the js file where the function to be called is in....
$crud->post_ajax_callbacks('do_the_sum()'); // Here i register the function to be called back... 

now grocery crud will make a call to the function everytime after the ajax data is loaded and it will serve the purpose to you.

 

Happy GCing:)



#3 MD Rahat Islam Khan

MD Rahat Islam Khan

    Member

  • Members
  • PipPip
  • 13 posts

Posted 16 March 2014 - 07:12 AM

thanks a lot bro..it works nicely....



#4 Amit Shah

Amit Shah

    grocery CRUD Master

  • Advanced Member
  • PipPipPip
  • 1,192 posts
  • LocationMumbai, India

Posted 16 March 2014 - 03:00 PM

with pleasure my friend.. with pleasure



#5 HasanB

HasanB

    Newbie

  • Members
  • Pip
  • 3 posts
  • LocationSumenep-Indonesia

Posted 10 January 2021 - 01:59 PM

how it work in grocery enterprise 2,8,7 (bootsrap)?







Also tagged with one or more of these keywords: row, total

0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users