I used Math formulas with Script to calculate the product of two columns (price quantity)
---- mygrid.setColTypes("ed,ed,ed,ed[=c1c2]");
Also, I make a subtotal to sum the value of three rows by using math calculation in xml file.The coding is below:
when i input new values in price column and quantity column, the subtotal will be updated.However,there is no change in "amount "column where I set Math formulas here. why the product of column 1 value and column 2 value is not changed?
XML with data shouldn’t contain values for cells which should be calculated. In other words your XML should be as follows (it seems you just forgot to delete them, as you have more cell tags per row than expected for some reason):
Our company bought one license of professional version of your product. When we are using your product,in our development project, we face some technical problems about math calculation.
We make one subtotal to sum the value of each row and the product of two columns (Price column* Quantity column=Amount column) respectively using dhtmlgrid 's math formula .When enter some values quantity column or price column, it is expected the values in Total and Amount column will be updated immediately. However ,amount values are NOT UPDATED .Our development project is in urgent production phase. Please answer our inquries as fast as you can. Thank a lot. The following sample.zip file is for your reference .
I used math formula in grid to calculate the sum of rows’ values. First math formula calculate the sum of first three rows. Second formula calculate the sum of first three rows. it is expected the value of both sum will be updated when I enter some value into frist three rows. However first sum doesn’t work and it cannot calculate the new sum.
I want to know whether the grid can support two or more calculations involved same cells and Is there any method to do two or more calculation involved same cells .My coding is below. Thank a lot .
Thank you for your fast reply.I doubt whether it can work or not when I add more subtotal (math formula) or I added more calculation about the product of two columns (ed[=c1c2])
For example I add more columns. if i set (ed[=c5c6]) in column 7 , can it work or not? Because we need to do a lot of calculation on product of two column. thank a lot.
First ,thank you for your fast answer. However, the problem cannot be solved completely. When I add more rows or/and columns in xml files and grids, the calculation problem come out again.
First problem come out when I enter some new value in ’ price1’ column and/or ’ quantity1’ column. Although the subtotal of ‘price 1’column and ‘quantity1 ‘columns can be updated in real time ,Subtotal of Amount1 column (product of ’ price1’ column and’ quantity1’ column) cannot be updated.
Second problem come out when add more rows or/and columns in xml files and grids.
when i enter some value in’ price2’ column and’ quantity2’ column, ‘Amount2’ column (product of ’ price2’ column and’ quantity2’ column) and ‘Amount2’ column’s subtotal cannot be updated. But I have already set mygrid.setColTypes(‘ed,ed,ed,ed[=c1c2],ed,ed,ed[=c4c5]’); in grid script.
I have new question on mygrid.attachFooter. I find the total of "amount " column cannot be updated when i enter some value into price and quantity column. My coding is attached.Thank a lot.
2.)is there any method to differ subtotal cell from other cells and will count it while summating in my sample???
3.)I used mygrid.attachEvent method to call two fuctions respectively in doAfterXMLLoading().calculateFooterValues() is for counting the total of each column and function(stage,id,ind) is for calculating the subtotal.
when I edit some cells, the total of “amount” field only updated on second editing of cells.How can I update the total of “amount field” each editing rather than second editing???Please refer to the attachment.Thanks
function doAfterXMLLoading(){
/gets all sub_total rows/ mygrid.forEachRow(getSub)
/this event is called when cell is edited/ //mygrid.attachEvent(“onEditCell”,calculateFooterValues); mygrid.attachEvent(“onEditCell”,function(stage,id,ind){
if(stage == 2){ var cell = mygrid.cells(id,3).cell; var cell2 = mygrid.cells(id,6).cell;
Your sample throughs some error so I couldn’t get it working. But the problem is in the way you set event handlers. I would not use attachEvent for calculateFooterValues, instead just call it at the end of function you set on onEditCell event while grid initialization.
As to your other questions:
1. you can save grid content as CSV (see export/import to CSV). Excel can open CSV files
2. As you probably see in email support response - you can try using treegrid and keep these values on different levels. Or you can use grid nd keep these valus in different columns
Also, please use single way of getting support - either KB or email. In other cases different people spend time with same questions from you. Thank you.
I used the following coding to calculate the total of all the rows. But I want to skip some subtotal rows. How can I skip some row of subtotal in function sumColumn() ??? i.e. Thanks.
function sumColumn(ind){ var out = 0; mygrid.forEachRow(function(id){ var cl = mygrid.getRowAttribute(id,“class”); if(cl&&cl.indexOf(“subtotal2”)!=-1){ var value = mygrid.cells(id,ind); if (!isNaN(value)&&!value=="") out+= parseFloat(value); } } return out; }