jQWidgets Forums
jQuery UI Widgets › Forums › Grid › Compare column cell B with column cell A, turn cell value to red if greater
Tagged: #jqwidgets-grid, grid, javascript grid, jquery grid
This topic contains 6 replies, has 2 voices, and was last updated by vnistala 8 years, 2 months ago.
-
Author
-
March 12, 2017 at 11:51 pm Compare column cell B with column cell A, turn cell value to red if greater #92187
Hello,
I have a grid where I’ve to compare the values from 2 columns if column cell value of B is greater than Cell value of A for that row then turn only the cell of row in column B to red.
I have code snippet which is tuning all the cell values to red, need your help on the same.var gridAdapter3 = new $.jqx.dataAdapter(sourcegrid3, { async: false, autoBind: true, loadError: function (xhr, status, error) { alert('Error loading "' + source.url + '" : ' + error); } }); //var statusId = 0; var cellRecords = gridAdapter3.records; var length = cellRecords.length; for (var i = 0; i < length; i++) { var record = cellRecords[i]; var nsla = Number(record.sla); var nresponsetime = Number(record.responsetime); console.log(nresponsetime); var statusSaver = function (row, columnfield, value) { statusId = value; } var cellsrenderer = function (row, columnfield, value, defaulthtml, columnproperties) { if (nresponsetime > nsla) { return '<span style="margin: 4px;float: ' + columnproperties.cellsalign + ';color: #ff0000;font-weight: bold">' + record.responsetime + '</span>'; } else return '<span style="margin: 4px; margin-right: 10px; font-size: 14px; float: ' + columnproperties.cellsalign + ';">' + value + '</span>'; } }
Any help is appreciated
Regards,
VenkatMarch 14, 2017 at 10:29 am Compare column cell B with column cell A, turn cell value to red if greater #92226Hello Venkat,
It is not appropriate to set “cellsrenderer” callback in the for loop.
Also, I would suggest you look at this demo:
http://www.jqwidgets.com/jquery-widgets-demo/demos/jqxgrid/gridcellclass.htm?light
Do you receive any error message?
You could check the data that you compare in the “if” statementBest Regards,
Hristo HristovjQWidgets team
http://www.jqwidgets.comMarch 15, 2017 at 8:08 am Compare column cell B with column cell A, turn cell value to red if greater #92253Hello Hristo,
Yes it makes sense, added the same in the grid cellclass.
I saw another example
http://www.jqwidgets.com/community/topic/grig-cell-styling/var cellclass = function (row, columnfield, value) { var QuantityPerUnit = $('#jqxgrid').jqxGrid('getcellvalue', row, "QuantityPerUnit"); var UnitPrice = $('#jqxgrid').jqxGrid('getcellvalue', row, "UnitPrice"); if (QuantityPerUnit <= UnitPrice) { return "red"; }; }
Followed the same in my code but getting the following error.
Uncaught Error: Invalid Selector – #jqxgrid! Please, check whether the used ID or CSS Class name is correct.
at m.fn.init.a.fn.(anonymous function) [as jqxGrid] (http://10.10.122.84:8080/sample-tabs/jqwidgets/jqxcore.js:7:55680)Appreciate your help and responses.
Regards,
VenkatMarch 15, 2017 at 9:14 am Compare column cell B with column cell A, turn cell value to red if greater #92256Hello Venkat,
This error shows when the widget selector is wrong. Please, check it.
Is the same selector “jqxgrid” when try to get value (“getcellvalue”) and the created Grid?Best Regards,
Hristo HristovjQWidgets team
http://www.jqwidgets.comMarch 16, 2017 at 7:07 am Compare column cell B with column cell A, turn cell value to red if greater #92273Hello Hristo,
Yes that’s what the error tells, so when i put jqxgrid in double quotes it worked.
var sla = $("#jqxGrid").jqxGrid('getcellvalue', row, 'sla');
I was trying some cool options from jqwidgets, like when we turn on the filter function in grid the chart should change based on the filter, but for some reason i’m getting blank in chart. Am i missing something.
example:$("#jqxGrid").on('filter', function () { var rows = $("#jqxGrid").jqxGrid('getrows'); var chart = $(chartContainer7).jqxChart('getInstance'); chart.source = rows; chart.update(); });
I would like to thank and appreciate for all the help provided so far.
Regards,
VenkatMarch 16, 2017 at 12:54 pm Compare column cell B with column cell A, turn cell value to red if greater #92280Hello Venkat,
Could you provide us more details?
I would ask to write topics to the relevant sections (about the Grid in the section of Grid and relevant for the Chart).Best Regards,
Hristo HristovjQWidgets team
http://www.jqwidgets.comMarch 17, 2017 at 6:52 am Compare column cell B with column cell A, turn cell value to red if greater #92296Sure thanks Hristo added a new post in charts section
http://www.jqwidgets.com/community/topic/chart-with-grid-not-working/
Regards,
Venkat -
AuthorPosts
You must be logged in to reply to this topic.