Author Topic: change cell styling programmatically  (Read 4343 times)

RedBully

  • Pro Deluxe
  • Jr. Member
  • *
  • Posts: 51
    • View Profile
change cell styling programmatically
« on: April 04, 2014, 01:47:14 am »
When a cell renders I want to change the styling of the cell based on some business rules. I see there is a property ''pq_cellcls" that is exposed declaratively. I imagine I can override this programmatically in JS by am unsure how?

VRfGPf_Pageobj.colModel = [
   { title: 'Label', editable: function (ui) { return oa.IsCellEditable(ui); },
render: function (ui) { return oa.RenderCell(ui); },
width: 200, dataType: 'text', validations: [
 {type: 'minLen', value: '1', msg: 'Label is mandatory'}
 ] }, ...

JS snippet:

    oa.RenderCell = function (ui) {

        var r = ui.rowIndx;
        var c = ui.column.dataIndx;

//how do I change the styling of the cell here?

Thanks.



paramvir

  • Administrator
  • Hero Member
  • *****
  • Posts: 6298
    • View Profile
Re: change cell styling programmatically
« Reply #1 on: April 04, 2014, 01:48:07 pm »
cell styles can be set using pq_cellcls only before rendering phase.

If it has to be set within cell render callback (i.e. during rendering phase), then you have to use addClass API and within setTimeout so that the cell style take place immediately after render phase.

Addition (10/03/2014)

cell styles can be set with pq_cellcls in column.render callback for the current cell since version 2.1.0 as shown in this demo

http://paramquery.com/pro/demos/render_cells
« Last Edit: October 03, 2014, 08:19:14 pm by paramquery »

dbadmin

  • Pro Economy
  • Jr. Member
  • *
  • Posts: 67
    • View Profile
Re: change cell styling programmatically
« Reply #2 on: October 03, 2014, 08:13:11 pm »
So which event should be used to change a style of a cell, to make sure it gets updated after loading new data, page change, sorting, etc.?
I'd like to highlight rows that have same data in a specific column (by dataIndx).

paramvir

  • Administrator
  • Hero Member
  • *****
  • Posts: 6298
    • View Profile
Re: change cell styling programmatically
« Reply #3 on: October 03, 2014, 08:21:56 pm »
It could be done in load event.

http://paramquery.com/pro/api#event-load

dbadmin

  • Pro Economy
  • Jr. Member
  • *
  • Posts: 67
    • View Profile
Re: change cell styling programmatically
« Reply #4 on: October 03, 2014, 08:27:12 pm »
I was under impression that local sorting does not trigger load event. Is it not the case?

paramvir

  • Administrator
  • Hero Member
  • *****
  • Posts: 6298
    • View Profile
Re: change cell styling programmatically
« Reply #5 on: October 03, 2014, 08:37:46 pm »
sorting does not trigger load event; it triggers sort event.

But sorting doesn't modify the data, it only changes the order of the rows, so it won't affect your logic to highlight the rows /cells.

Similar is the case with paging.

Assuming your data would be static ( in the sense it won't be inline edited or pasted or new rows added, etc ) once you load your data from remote server, you only need to listen to load event.
« Last Edit: October 03, 2014, 08:42:00 pm by paramquery »