Announcement

Collapse
No announcement yet.
X
  • Filter
  • Time
Clear All
new posts

    Parameters for Comparator?

    I'm trying to implement a comparator for a field. However, I am a bit confused as to how parameters are passed?

    Code:
    specDetailGrid.data.sort(comparator());
    
    function comparator(a, b) {
        isc.warn("hello " + a + " " + b);
    }
    is basically what I have. both a and b are undefined when executed. I'm not sure what variable names are available to pass to the function.

    Thanks

    #2
    It looks like you're expecting listGrid.data to be an Array, it's not, it's a ResultSet. See the ResultSet's docs for sortByProperty and look also at sortNormalizers - you don't pass in a comparator, you use this other APIs.

    Comment


      #3
      I used it because the 5.7.1 documentation shows ListGrid.data as a List or ListGridRecord. And the sort function was defined as List.sort([comparator]).

      Unfortunately, my problem is that I am trying to sort a date but defined slightly differently:
      Code:
      <field 
      name="period" 
      title="Date" 
      type="long" 
      valueXPath="period/periodId" 
      editorType="select" 
      optionDataSource="specDetailDates" 
      valueField="periodId" 
      displayField="displayFormat" />
      We need to do this due to special dates values (i.e. fiscal) we use. So the value is actually an ID, and the display is a string of the date. DisplayFormat is done in the DMI and returns MM/YYYY. I've tried simply returning the date instead of the displayFormat then updating the formatCellValue but it does not register date functions (i.e. date.getMonth()). Tried setting up the Date.formatters but no success. My assumption is because the field type is of Long.

      My guess is that I may need to figure a way to update the valueMap of the field.
      Last edited by dleung; 10 Aug 2010, 09:15.

      Comment


        #4
        Yes, the docs say ListGrid.data is a List because ResultSet "isA" List.

        This doesn't seem to have anything to do with comparators - you've got an optionDataSource, so the order is which it returns data records is the order that they will be displayed. So you have complete control, server-side, to do whatever sorting you want.

        Comment


          #5
          yes but the problem was after updating the ListGrid, the sorting becomes off. I think our solution thus far is to simply go off the ID as long as they stay in sequential order.

          Comment

          Working...
          X