jQWidgets Forums
jQuery UI Widgets › Forums › Grid › Aggregates with empty Grid.
This topic contains 3 replies, has 2 voices, and was last updated by jose Ivan 12 years, 7 months ago.
-
Author
-
Hi, i I was wonder what’s happen when the grid is empty. I added a validation to set aggregates when it’s undefined the value return 0.
the problem it’s when i change the value it’s doesn’t change aggregate value alwayas is undefined.
My scenary is that i bind the grid and then a fill the grid with empty rows until rowcounts is 11
when i cellendedit I think the aggregate have to refresh.I added the 2 function refreshaggregate and renderaggregate.
$("#jqxgrid").jqxGrid( { width: 670, source: dataAdapter, theme: theme, pageable: true, autoheight: true, editable :true showstatusbar: true, statusbarheight: 25, showaggregates: true, columns: [ { text: 'First Name', datafield: 'firstname', width: 100 }, { text: 'Last Name', datafield: 'lastname', width: 100 }, { text: 'Product', datafield: 'productname', width: 190 }, { text: 'cantidad', datafield: 'total_count', width: 90, cellsalign: 'right', aggregates:[{'total_count': function(Value, currentValue, column, record) { var a= currentValue!='' || typeof currentValue !=undefined ? currentValue :0; var b= Value!='' || typeof Value !=undefined ? Value :0; return a+b; } }], aggregatesrenderer :function(aggregates) { var renderstring = aggregates['total_count']; if typeof renderstring !=undefined return '<span style="margin-top: 4px; float: right;"><strong> Total : ' + renderstring + '</strong></span>'; else return '<span style="margin-top: 4px; float: right;"><strong> Total : ' + parseFloat(0) + '</strong></span>'; }, validation: function (cell, value) { try { var myresult = eval(value.toString()); if(myresult>15 and myresult<150)return true; else return false } catch (err) { return { result: false, message: 'Error en la digitación...' }; } } } { text: 'Price', datafield: 'price', width: 90, cellsalign: 'right', cellsformat: 'c2' } ] }); $("#jqxgrid").bind("bindingcomplete", function (e) { var a = 10 - config.numrows; // NUM OF ROWS FROM SERVER for (var b = 0; b <= a; b++) { methods.insertrow();// INSERT A NEW ROW methods.AddCountRows(); } $("#jqxgrid").jqxGrid('refresheaggregates'); $("#jqxgrid").jqxGrid('renderaggregates'); $(".currency").formatCurrency({ symbol: " " }); }); $("#jqxgrid").bind("cellvaluechanged", function (a) { $(".currency").formatCurrency({ symbol: " " }); var column = args.datafield; if (column != "indice" && column != "ready") { var row = args.rowindex; var value = args.value; var oldvalue = args.oldvalue; if (methods.validateInsert(row)) { var b = methods.getlastroweditable(); b = row < b ? b : row + 1; methods.SetlastRowEditable(b); } $("#jqxgrid").jqxGrid('refresheaggregates'); $("#jqxgrid").jqxGrid('renderaggregates'); $(".currency").formatCurrency({ symbol: " " }); } $(".currency").formatCurrency({ symbol: " " }); }); is there a way to update the render aggregates or any method to update this value in each column.
The issue here is that aggregates expect numeric data. With textbox editor, you enter only string data i.e “54” instead of 54. Use the Grid’s numeric editors for editing numeric data and aggregates will be calculated automatically.
Best Regards,
Peter StoevjQWidgets Team
http://www.jqwidgets.comThanks for reply … the problem it’s that i added some key like ‘+,-,*,/’ so the final user can do operations with strings like “2+2” and validation function it’s solve the string and put 4 .
if i change the typetextbox to numeric i have to add some code to let writes the keycode.
Can i change the columntype to numeric in cellendedit and initeditor change to textbox?
-
AuthorPosts
You must be logged in to reply to this topic.