Author Topic: changing cell css in colModel.render  (Read 3897 times)

Leo F

  • Pro Enterprise
  • Newbie
  • *
  • Posts: 21
    • View Profile
changing cell css in colModel.render
« on: March 05, 2014, 02:12:22 am »
I have the following code. Basically I need to change the class of a cell based on the value.

col.render = function (ui) {
                            var noVal = false;
                            if (ui.cellData == null || ui.cellData == "")
                                noVal = true;

                            if (grid.Container.pqGrid("hasClass", { rowIndx: ui.rowIndx, cls: 'gridRowTieDiff' })) {
                                if (noVal || ui.cellData == "0") {
                                    grid.Container.pqGrid("removeClass", { rowIndx: ui.rowIndx, dataIndx: ui.dataIndx, cls: 'gridCellTieFailed' });
                                } else {
                                    grid.Container.pqGrid("addClass", { rowIndx: ui.rowIndx, dataIndx: ui.dataIndx, cls: 'gridCellTieFailed' });
                                }
                            }

                            if (noVal)
                                return null;

                            return "$" + parseInt(ui.cellData).toLocaleString();
                        };


This does not quite work because this event is apparently called after the grid refresh happens, and so the styles actually that get added/removed take effect on the next refresh.
Adding
grid.Container.pqGrid("refreshCell", { rowIndx: ui.rowIndx, dataIndx: ui.dataIndx });
creates infinite recursion.
Is there another way to do this?
« Last Edit: March 05, 2014, 02:14:47 am by Leo F »

paramvir

  • Administrator
  • Hero Member
  • *****
  • Posts: 6310
    • View Profile
Re: changing cell css in colModel.render
« Reply #1 on: March 05, 2014, 10:15:51 am »
You could put it in a window.setTimeout. refreshCell is not required.
« Last Edit: March 05, 2014, 10:19:51 am by paramquery »

Leo F

  • Pro Enterprise
  • Newbie
  • *
  • Posts: 21
    • View Profile
Re: changing cell css in colModel.render
« Reply #2 on: March 05, 2014, 10:19:41 am »
Put grid.Container.pqGrid("refreshCell", { rowIndx: ui.rowIndx, dataIndx: ui.dataIndx }); in a setTimeout? How would that help?

paramvir

  • Administrator
  • Hero Member
  • *****
  • Posts: 6310
    • View Profile
Re: changing cell css in colModel.render
« Reply #3 on: March 05, 2014, 10:24:19 am »
refreshCell is not required as addClass and removeClass takes care of refreshing the cell view.

You can wrap the code where you make changes to the view i.e. addClass and removeClass in a setTimeout so that it executes after the whole / partial view has been rendered.