Announcement

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

    Unexpected ListGrid behaviour with setSortNormalizer() and setSortField() (Bug?)

    Hi Isomorphic,

    I just wanted to let you know that I spotted some unexpected behaviour with ListGrids (not really a bug I'd guess):
    .java (excerpt)
    Code:
    boundList = new ListGrid() {{
    setSortField("STATUS_POSITION");
    ListGridFieldStatus statusLGF = new ListGridFieldStatus("STATUS_ID", false, false);
    statusLGF.setSortByDisplayField(false);
    statusLGF.setSortNormalizer(new SortNormalizer() {
    	@Override
    	public Object normalize(ListGridRecord record, String fieldName) {
    		return record.getAttributeAsInt("STATUS_POSITION");
    	}
    });
    .ds.xml
    Code:
    <field name="STATUS_ID" title="Status" type="int" displayField="STATUS_SHORTNAME" canEdit="false" tableName="V_PERSON_STATUS" />
    <field name="STATUS_POSITION" title="Status Position" canEdit="false" hidden="true" type="int" tableName="V_PERSON_STATUS" />
    <field name="STATUS_SHORTNAME" title="Statusname" canEdit="false" hidden="true" type="text" length="50" tableName="V_PERSON_STATUS"
    			escapeHTML="true" />
    As you can see, I show the STATUS_ID field, which has a displayField of STATUS_SHORTNAME and is sorted on click via STATUS_POSITION (because of the SortNormalizer).
    The setSortField("STATUS_POSITION") sorts the Gird on start, BUT, as I sort by the not shown field "STATUS_POSITION", no sort indicator is shown. This is perfectly fine for me.
    If it weren't I'd say "Sort by STATUS_ID", which means replace setSortField("STATUS_POSITION") by setSortField("STATUS_ID").

    This is not possible. Although no error is shown anywhere, the sort on start is by displayField and also a click on the column header sorts by displayField and not STATUS_POSITION. The SortNormalizer is not accessed, breakpoints within are not hit.

    For me, it is no problem, as the workaround is 99% fine (it's just missing the sort indicator), but you might want to look into this nevertheless.

    Also it would be great if you updated the docs with some information on the precedence of setSortByDisplayField and setSortNormalizer, especially "Do I have to set setSortByDisplayField(false) when using setSortNormalizer".

    Best regards,
    Blama

    PS: I'm on FF 11.0, Eclipse Dev Mode with v8.2p_2012-05-30/EVAL Deployment 2012-05-30

    #2
    I think I found the cause:

    You have to *always* call setSort() AFTER setFields().
    @Isomorphic: Is this true?

    If I do, I have it now working as I wanted with
    - sorted at start
    - sort by SortNormalizer
    - sort indicators (on my ID column using a display field, but sorted via SortNormalizer)

    And as a pointer for anyone reading this:
    If you want to keep your ListGrid sorted after any DML, use ListGrid.getResultSet().addDataChangedHandler() and re-sort from there.

    Thanks,
    Blama

    Comment

    Working...
    X