Display the total below the grid

Hi,

I developed a grid having the field LOB and percentage for each project id in the Project table form. Please let me know with a sample code for creating a text box or a field below the grid having the total of the percentage column of all LOB respective to the project id. When the user inserts a line with thje lob and percentage then the text to be filled automatically with the the total.With the same total field i need to write a validation method saying that it should not be less than 100.

Thanks…

Hi,

Can u please elaborate more, your query is not clear !

Hi,

I have a grid with lob and percentage as a 2 column in it. User fills the lob and percentage for each project. For example a user selects a project from the project table . They will fill either single lob or multiple lob with percentage. I need a field or a text box below the grid showing the total of all the percentage of lob for the selected project. Hope its clear. If not let me know.

Thanks

Hi,

You can use the QueryRun Class as in the following code, it sums col values and display it under the grid. it’s in your form datasource executeQuery() method:

queryRun qrTotal;

YourTable YourTable;

;

qrTotal = new queryRun(YourFormDatasource_ds.queryRun().query());
qrTotal.query().dataSourceNo(1).addSelectionField(fieldnum(Datasource,field_To_Sum),SelectionField::Sum);
qrTotal.query().dataSourceNo(1).addRange(fieldnum(Datasource,ItemId)).value("!some value*");//You can add range to filter values to sum

while(qrTotal.next())
{
YourTable= qrTotalM2.get(tablenum(YourTable));
FieldUnderTheGrid.realValue(YourTableP.YourField);
}

Regards,

Thomas

Hi Thanks for the response . But it did not work. I coudnt get the queryrun() from the Datasource table . My table is projtable by ther was no queryRun() funtion

Thanks…

I don’t speak about table method but form datasource method, if you right-click on your form DataSource on the projTable table and select override method, you’ll find executeSection() method and in this method, if you use the syntax projTable_ds (referring to the ProjTable datasource from your form), you’ll access to the QueryRun method in autocompletion. It should give the following:

qrTotal = new queryRun(ProjTable _ds.queryRun().query());
qrTotal.query().dataSourceNo(1).addSelectionField(fieldnum(ProjTable ,field_To_Sum),SelectionField::Sum);
qrTotal.query().dataSourceNo(1).addRange(fieldnum(ProjTable ,ItemId)).value("!some value*");

while(qrTotal.next())
{
ProjTable = qrTotalM2.get(tablenum(ProjTable ));
FieldUnderTheGrid.realValue(ProjTable .YourField);
}

Don’t forget to set the autodeclaration property to yes for the field you want to add under your grid, otherwise, you won’t access to the realValue() method.

Regards,

Thomas

Hi,

Sorry my table name is caeProjLob.I wrote the above code with the caeProjLob table. But what this ItemId value?

qrTotal.query().dataSourceNo(1).addRange(fieldnum(ProjTable ,ItemId)).value("!some value*");

Because i have only 3 fields in the caeprojlob table.Lob ,Percentage ,Projid.Please let me know whats that Item id field?

Thanks…

ItemId is an example to show how to add filters on query, if you don’t want to filter your datasource, just comment this line

Thanks for your response .But i was getting an issue in the following line like Table does not contain this field.

caeProjLob = qrTotalM2.get(tablenum(caeProjLob)

Hi,

your error comes from QrTotalM2, I quickly copy paste my code from a dev I did and I forget to correct the value in the while loop, try with qrTotal in place of qrtotalM2

regards

Ya I noticed and corrected it. But the field created for the Table caeProjLob as Total for the field under the grid to be displayed with total. But it is not recognized from the method.

Total.realValue(caeProjLob.Percentage);

you don’t need to add a field for total in your table, in your exemple Total refer to the field object in your form, just add it in your design and set the autodeclaration property to yes, realValue method set the value displayed in your form field, about the field you created in your table for the sum value, it’s a non sense because it won’t have be record relative

Hi Thomas,

Can you send an example code please… i didnt sucsess…

public void executeQuery()

{

QueryRun qrTotal;

MytmpTable mytmptable;

super();

qrTotal = new QueryRun(MytmpTable_ds.queryRun().query());

qrTotal.query().dataSourceNo(1).addSelectionField(fieldNum(MytmpTable,Field1),SelectionField::Sum);

While(qrTotal.next())

{

mytmptable = qrTotal.get(tableNum(MytmpTable));

info(int2str(mytmptable.Field1));

}

}

Recep, please don’t use use the solution that requires iterating through all rows; it’s much worse than what I suggest in your thread (How to sum grid column value?). And please keep the discussion there, I’m not going to copy my answer to many threads.

ok… :frowning: