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
Add a extra row for calculating total for few tables
- Single Page
Posted 05 March 2014 - 03:57 AM
Posted 05 March 2014 - 13: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> </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:)
Posted 16 March 2014 - 07:12 AM
thanks a lot bro..it works nicely....
Posted 16 March 2014 - 15:00 PM
with pleasure my friend.. with pleasure
Posted 10 January 2021 - 13:59 PM
how it work in grocery enterprise 2,8,7 (bootsrap)?