jQWidgets Forums
jQuery UI Widgets › Forums › Grid › calculate sum of column values in jqgrid
Tagged: aggregates, getcolumnaggregateddata, grid, jqxgrid, statusbar, sum
This topic contains 7 replies, has 2 voices, and was last updated by Dimitar 10 years, 10 months ago.
-
Author
-
hi
i have a grid which contain a column called “PRICE”.
is it possible to calculate sum of all the values in “PRICE” column?
Hello sathiyaseelan8,
Yes, this is possible via the grid aggerates functionality. Here is a link to the demo:
http://www.jqwidgets.com/jquery-widgets-demo/demos/jqxgrid/aggregates.htm?arcticBest Regards,
DimitarjQWidgets team
http://www.jqwidgets.com/thanks dimitar. i managed to do it.
once i did the aggerates function, my status bar in the grid gone missing.
is there a way to maintain both(aggerates & status bar) in a grid?
Hi sathiyaseelan8,
You can find the answer in the forum topic Aggregates and Statusbar together – is it possible?
Best Regards,
DimitarjQWidgets team
http://www.jqwidgets.com/hi dimitar
seems we cannot maintain both (aggerates & status bar) in a grid, is there a way where i can get the sum and display it on a textbox?
Hi sathiyaseelan8,
This can be achieved by using the method getcolumnaggregateddata:
var summaryData = $("#jqxGrid").jqxGrid('getcolumnaggregateddata', 'quantity', ['sum']);
An example can be found here.
Best Regards,
DimitarjQWidgets team
http://www.jqwidgets.com/hi dimitar,
i still couldn’t abble to get the sum.
here is my code.
var othr_mod = function (maint_no){ var clnt_cod = document.getElementById('clnt_cod').value; var source = { datatype: "json", id: 'sq_no', url: 'include/display_maint_tab.php?dis_othr_mod=true&maint_no='+maint_no, addrow: function (rowid, rowdata, position, commit) { var maint_no = document.getElementById('input_maint_no').value; var data = "add_othr_mod=true&maint_no="+maint_no+"&clnt_cod="+clnt_cod; alert(data); $.ajax({ datatype: 'json', type: 'get', url: 'include/display_maint_tab.php', data: data, success: function (data, status, xhr) { // update command is executed. commit(true); document.getElementById('input_maint_no').value = data; othr_mod(data); }, error: function () { // cancel changes. commit(false); } }); }, datafields: [ { name: 'mod_name' }, { name: 'cont' }, { name: 'price' } ], updaterow: function (rowid, rowdata, position, commit) { var data = "update_othr_mod=true&row_id="+rowid+"&mod="+rowdata.mod_name+"&cont="+rowdata.cont+"&price="+rowdata.price; alert(data); $.ajax({ dataType: 'json', url: 'include/display_maint_tab.php', data: data, success: function (data, status, xhr) { // update command is executed. commit(true); }, error: function () { // cancel changes. commit(false); } }); }, deleterow: function (rowid, rowdata, position, commit) { var data = "del_othr_mod=true&row_id="+rowid; $.ajax({ dataType: 'json', url: 'include/display_maint_tab.php', data: data, success: function (data, status, xhr) { // remove command is executed. othr_mod(maint_no); commit(true); }, error: function () { // cancel changes. commit(false); } }); }, }; var cellbeginedit = function (row, datafield, columntype, value) { if (datafield == 'comp_date' || datafield == 'stat' || datafield == 'job_id' || datafield == 'se' || datafield == 'scr_no') return false; } var dataAdapter = new $.jqx.dataAdapter(source); // initialize jqxGrid $("#jqxgrid").jqxGrid( { width: '100%', //height: 600, autoheight: true, source: dataAdapter, editable: true, selectionmode: 'singlerow', //editmode: 'selectedrow', theme: theme, //showaggregates: true, showstatusbar: true, renderstatusbar: function (statusbar) { // appends buttons to the status bar. var container = $("<div style='overflow: hidden; position: relative; margin: 5px;'></div>"); var addButton = $("<div style='float: left; margin-left: 5px;'><img style='position: relative; margin-top: 2px;' src='../main_include/images/add2.png'/><span style='margin-left: 4px; position: relative; top: 0px;'>Add</span></div>"); var deleteButton = $("<div style='float: left; margin-left: 5px;'><img style='position: relative; margin-top: 2px;' src='../main_include/images/close.png'/><span style='margin-left: 4px; position: relative; top: 0px;'>Delete</span></div>"); var reloadButton = $("<div style='float: left; margin-left: 5px;'><img style='position: relative; margin-top: 2px;' src='../main_include/images/refresh.png'/><span style='margin-left: 4px; position: relative; top: 0px;'>Reload</span></div>"); //var searchButton = $("<div style='float: left; margin-left: 5px;'><img style='position: relative; margin-top: 2px;' src='../main_include/images/search.png'/><span style='margin-left: 4px; position: relative; top: 0px;'>Find</span></div>"); container.append(addButton); container.append(deleteButton); container.append(reloadButton); //container.append(searchButton); statusbar.append(container); addButton.jqxButton({ width: 60, height: 15, theme: theme }); deleteButton.jqxButton({ width: 65, height: 15, theme: theme }); reloadButton.jqxButton({ width: 65, height: 15, theme: theme }); //searchButton.jqxButton({ width: 50, height: 15, theme: theme }); // add new row. addButton.click(function (event) { var commit = $("#jqxgrid").jqxGrid('addrow', {}, {}); }); // delete selected row. deleteButton.click(function (event) { var selectedrowindex = $("#jqxgrid").jqxGrid('getselectedrowindex'); var rowscount = $("#jqxgrid").jqxGrid('getdatainformation').rowscount; var id = $("#jqxgrid").jqxGrid('getrowid', selectedrowindex); var commit = $("#jqxgrid").jqxGrid('deleterow', id, {}); }); // reload grid data. reloadButton.click(function(event) { othr_mod(document.getElementById('input_maint_no').value); }); // search for a record. /* searchButton.click(function (event) { var offset = $("#jqxgrid").offset(); $("#jqxwindow").jqxWindow('open'); $("#jqxwindow").jqxWindow('move', offset.left + 30, offset.top + 30); });*/ }, //selectionmode: 'singlecell', columns: [ { text: 'Item', datafield: 'mod_name'}, { text: 'Sub Contractor', datafield: 'cont', width: 130 }, { text: 'Price', datafield: 'price', width: 80} ] }); };
Hello sathiyaseelan8,
Please specify the type of your source datafields and try again (with the getcolumnaggregateddata method), i.e.:
datafields: [{ name: 'mod_name', type: 'string' }, { name: 'cont', type: 'string' }, { name: 'price', type: 'number' }],
Best Regards,
DimitarjQWidgets team
http://www.jqwidgets.com/ -
AuthorPosts
You must be logged in to reply to this topic.