ParamQuery grid support forum

General Category => Help for ParamQuery Pro => Topic started by: nuno.nogueira on February 06, 2014, 06:26:33 pm

Title: Calculated column
Post by: nuno.nogueira on February 06, 2014, 06:26:33 pm
The last column of my table is a calculated field (the difference between the two previous columns).

When users add a row:
Title: Re: Calculated column
Post by: paramvir on February 06, 2014, 07:01:28 pm
1) If it's for view purpose only, then you can use column.render callback to calculate the field. And keep column.editable to false to disallow editing.
http://paramquery.com/pro/api#option-column-render
http://paramquery.com/pro/api#option-column-editable

2) use column.cls
http://paramquery.com/pro/api#option-column-cls
Title: Re: Calculated column
Post by: nuno.nogueira on February 06, 2014, 08:36:35 pm
(I've attached the question, since it isn't being posted correclty here)

This is the definition of the column:

[code]colModel: [
{ title: "Desvio", width: 100, dataType: "float", align: "right", dataIndx: "desvio", cls:'coluna_calc', editable: false, render:function(ui){return "
Title: Re: Calculated column
Post by: paramvir on February 06, 2014, 08:47:16 pm
Please refer to this live example ( css tab) for adding cls in the column.

http://paramquery.com/pro/demos/selection_checkbox

Code: [Select]
render : function(ui){
  return (ui.rowData["revenue"] - ui.rowData["expenses"]);
}
Title: Re: Calculated column
Post by: nuno.nogueira on February 06, 2014, 10:12:04 pm
The calculation is working OK after refreshing the table, but I was trying to have the calculation ready whenever any of the numbers in the columns were updated. I guess I need an event for cell change AND a callback function for that.

As for adding the class to the column, no matter what I do, it doens't get added. This is what I have in colModel:

Code: [Select]
{ title: "Desvio", width: 100, dataType: "float", align: "right", dataIndx: "desvio", cls:'coluna_calc', editable: false}
Title: Re: Calculated column
Post by: paramvir on February 06, 2014, 11:49:34 pm
Use cellSave event to call refreshCell for the computed cell.

http://paramquery.com/pro/api#event-cellSave
http://paramquery.com/pro/api#method-refreshCell


Did you check whether class is injected in the column using DOM inspector.

EDIT:
============================================================
I see that class has been added in the column. You have to make change in css for it to take effect.

Code: [Select]
.pq-grid .coluna_calc {
  color: red;
}
Title: Re: Calculated column
Post by: nuno.nogueira on February 07, 2014, 06:12:45 pm
Yes, class has been added, thanks!  :D

I'm now checking cellSave and refreshCell
Title: Re: Calculated column
Post by: nuno.nogueira on February 11, 2014, 05:16:15 pm
(Here's the question in attahcment)

Hi,

I have to get back to the calculated column issue, sorry..

The question is, how do I trigger the function to calculate column "desvio", whenever cells in columns "atual" or "orcamento" are saved locally?

I assume the cellSave event has to included in these two columns, but how do I call the function?

This is what I have in colModel:

Code: [Select]
colModel: [
{ title: "Or
Title: Re: Calculated column
Post by: paramvir on February 11, 2014, 05:44:28 pm
just call refreshCell ( {dataIndx :'desvio', rowIndx:ui.rowIndx}) or refreshRow( {rowIndx: ui.rowIndx}) from cellSave event.
Title: Re: Calculated column
Post by: nuno.nogueira on February 11, 2014, 06:31:11 pm
Yes, calculated field in on, thanks!
 :)