jQWidgets Forums
jQuery UI Widgets › Forums › Grid › Cellformat based on another column value
Tagged: angular grid, bootstrap grid, grid cellformat, javascript grid, jquery grid, jqwidgets grid, jqxgrid
This topic contains 3 replies, has 2 voices, and was last updated by Hristo 8 years, 9 months ago.
-
Author
-
Hello.
I’m trying to put a dynamic cell formating based on another colum value. Some rows I want to display currency, another ones percentage.
This is what I tried so far:
var dataAdapter = dataAdaptersourceanlevofam; var cellclassname = function (row, column, value, data) { if (data.nome != "") { return "grayline"; }; }; var cellformat = (function (row, column, value, data) { if (data.year!= "Evo") { return "c0"; } else { return "p2"; } })(); $("#jqxgridanl").jqxGrid({ source: dataAdaptersourceanl, theme: 'Metro', height: 600, width: '100%', sortable: true, columnsresize: true, showaggregates: false, showstatusbar: true, statusbarheight: 25, altrows: false, showtoolbar: true, columns: [ { text: 'Family', dataField: 'family', width: 240, sortable: false, cellclassname: cellclassname }, { text: 'Year', dataField: 'year', width: 50, sortable: false, cellclassname: cellclassname }, { text: 'M1', dataField: 'm1', width: 110, align: 'right', cellsalign: 'right', sortable: false, cellclassname: cellclassname, cellsformat: cellformat } ] });
But when I run this code I get
“Uncaught TypeError: Cannot read property ‘year’ of undefined”The cellclassname function is working fine.
Any pointers?
Hello xixo,
Only string could set on cellsformat, with possible values that could see in our API Documentation.
About that you want to achieve could usecellsrenderer: function (row, columnfield, value, defaulthtml, columnproperties) { //Do Something }
Please, take a look this example:
http://www.jqwidgets.com/jquery-widgets-demo/demos/jqxgrid/defaultfunctionality.htm?lightBest Regards,
Hristo HristovjQWidgets team
http://www.jqwidgets.comThanks for the tip.
Just put it on cellsrenderer, like this:
var dataAdapter = dataAdaptersourceanlevofam; var cellclassname = function (row, column, value, data) { if (data.nome != "") { return "grayline"; }; }; $("#jqxgridanl").jqxGrid({ source: dataAdaptersourceanl, theme: 'Metro', height: 600, width: '100%', sortable: true, columnsresize: true, showaggregates: false, showstatusbar: true, statusbarheight: 25, altrows: false, showtoolbar: true, columns: [ { text: 'Family', dataField: 'family', width: 240, sortable: false, cellclassname: cellclassname }, { text: 'Year', dataField: 'year', width: 50, sortable: false, cellclassname: cellclassname }, { text: 'M1', dataField: 'm1', width: 110, align: 'right', cellsalign: 'right', sortable: false, cellclassname: cellclassname, cellsrenderer: function (row, column, value) { var valor = $("#jqxgridanlevofam").jqxGrid('getcellvalue', row,'ano'); if (valor != 'Evo') { value = $.jqx.dataFormat.formatnumber(value, 'c0'); } else { value = $.jqx.dataFormat.formatnumber(value, 'p2'); } return '<span style="margin: 4px; float: right;">' + value + '</span>';} ] });
But now I’ve got another problem, which is the currency format.
Usually I put:var localizationobj = {}; localizationobj.currencysymbol = " €"; localizationobj.currencysymbolposition = "after"; $("#jqxgridanl").jqxGrid('localizestrings', localizationobj);
after creating the grid, but now it doesn’t work as it allways puts the “$” character.
Thanks.
Hello xixo,
Could you try to use whole custom logic. You could set directly desirable string (for example:
value = 12€
orvalue = 12.12%
).Best Regards,
Hristo HristovjQWidgets team
http://www.jqwidgets.com -
AuthorPosts
You must be logged in to reply to this topic.