jQWidgets Forums
jQuery UI Widgets › Forums › Grid › Grid balance
This topic contains 7 replies, has 2 voices, and was last updated by taskmate 8 years, 11 months ago.
-
AuthorGrid balance Posts
-
Please excuse the English translation that makes Google Translate
I have to solve the following:
In the “A” column I have a string, in the “B” and “C” column I have numerical values. The “D” column should reflect the calculation of the column “B” minus the “C” column, where the “A” column has the same value. An example below.A B C D Data 1 10 2 8 Data 1 2 6 Data 2 50 2 48 Data 2 10 38
To be clear, I need a balance. It is very important that the “D” column format is maintained, in this case, right-aligned and formatted d2
Best Regards,
Sergio HauratSir
This may not be the best as the code but what I suggest is
$(‘#jqxgrid’).on(‘bindingcomplete’, function (event) {
var rows = $(‘#jqxGrid’).jqxGrid(‘getrows’);
for (var i = 0; i < rows.length ; i++){
var bvalue = rows[i][‘b’];
if (i ==0){
if (!bvalue){bvalue = 0;}
} else {
bvalue = rows[i-1][‘d’];
}var cvalue = rows[i][‘c’];
if (!cvalue){cvalue = 0;}
var dvalue = parseInt(bvalue) – parseInt(cvalue);
$(“#jqxgrid”).jqxGrid(‘setcellvalue’, 0, “d”, dvalue);
}
});Thanks for your suggestion, that you propose would happen in “bindingcomplete” would be best to do it on “cellsrenderer” or “renderer” it is much difference between a performance and a method.
Hi
I am not sure but bindingcomplete would be called once and cellrender would be called [no of rows * no of columns];
But if there is problem on bindingcomplete obviously it can be called on cellrender
Regards
I develop a function in javascript, the problem is that when update the value in the cell, the format is “destroyed” completely
Hi
Have you tried using
var cellsrenderer = function (row, columnfield, value, defaulthtml, columnproperties) {
if (value < 20) {
return ‘<span style=”margin: 4px; float: ‘ + columnproperties.cellsalign + ‘; color: #0000ff;”>’ + value + ‘</span>’;
}
else {
return ‘<span style=”margin: 4px; float: ‘ + columnproperties.cellsalign + ‘; color: #008000;”>’ + value + ‘</span>’;
}
}Regards
@taskmate, I saw that code but does not respect the format of the cell, I have thousands and decimal separator.
SysProfile
You create the string with said format and pass the value to the grid as string. If the data type is string column will not change format.
Sanjay
-
AuthorPosts
You must be logged in to reply to this topic.