datasource
2011-09-23T02:38:37Z
Hi,

I have just downloaded demo version and evaluating the grid ActiveX. So far it is great. Here's a small dilemma I'm not sure how to deal with.
I'm using .FillFromRS method to populate grid. I have a column in my query that contains an integer representing number of minutes. I need display it in the grid as "Xh Ym", i.e. value of 93 min will display as 1h 33m. I'm not sure if this can be accomplished by using a format string. You can say - create a function in your query, so it will already include this value formatted this way, however then sorting on that column won't be proper, I need to sort on numeric value. In my existing project I use ListView control which obviously populated in code looping through recordset. In that case I use simple function:

Public Function toHourMin(intMinutes As Long) As String

  Dim intHours As Integer
  
  intHours = intMinutes / 60
  intMinutes = intMinutes Mod 60
  
  If intHours = 0 Then
    toHourMin = intMinutes & "m"
  Else
    toHourMin = intHours & "h " & intMinutes & "m"
  End If
  
End Function
Then I add value received from the function to a visible subitem and use Format(intMinutes, "000000") and stick it in hidden subitem. When user clicks on the column header, the sort index is set to hidden column. So I have grid displaying what I need and being sorted properly. Hope my explantion makes sense. Any ideas how to accomplish this in iGrid?

Thanks
Igor/10Tec
2011-09-23T06:46:21Z
iGrid has a special feature to do what you need. It is called the CellDynamicText event. The idea is to have data in your native format and convert them on the fly to output on the screen. In your case, the number of minutes will be stored in the required integer format, but your users will see a suitable "H:MM" representation on the screen you do in the CellDynamicText event handler. When the user clicks this column's header, the data are sorted as numbers - what we need.

Note that this approach works very fast even for big grids (10,000+, or even 100,000+ records) because the conversion in CellDynamicText is performed only for the cells visible in the iGrid viewport!
datasource
2011-09-23T07:26:27Z
It works, thank you for advise. However, the grid slows down considerably. Even when I commented the code in event procedure it was still slow. Only when I commented the whole event procedure, scrolling speed restored to normal. I guess event firing by itself is pretty heavy load. I'm thinking maybe I can still use approach similar to the one I used for listview - have two separate columns in my recordset - one with numeric values and another with string values formatted "h:mm". Then hide column with numeric values and somehow hook onto column click event in grid and change sorting column in code? Is it possible? Could be faster...

And one more thing while we are on the topic. I noticed that after grid is reloaded with new data, even that last dataset was sorted on some column (column header still shows sorting icon), the data are not sorted. Sorting occurs only when I click on column header again. Is there way to force sorting right after data is loaded into grid?
datasource
2011-09-23T21:29:16Z
OK, I think I found the right solution - using igSortCustom setting for the column and using CustomSort event. So basically I store and display strings in that column like "15h 23m", but when custom sort fires it converts back to integer. Obviously sorting on that column is slower than other columns, but acceptable. Thank you for your help.