Announcement

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

    Bug: Sort by date broken

    Hi Isomorphic,

    please see this minimal testcase on how sort on datefields (or even more?) is broken:

    Error 1:
    1) Load page, dates sorted, sort icon shown
    2) Change dates, sorting still correct, sort icon shown
    3) Click header to sort (sort direction changes, icon does NOT)
    4) Change dates, no more sorting, sort icon gone

    Error 2:
    1) Un-comment setCanSort(false);
    2) Load page, dates sorted, no icon shown!
    3) Change dates, sorting still correct, no sort icon shown!

    Error 3:
    1) Un-comment setCanSort(false); and setFields(datumLGF);
    2) Load page, dates sorted, no icon shown!
    3) Change dates, no sorting

    Java:
    Code:
    package com.smartgwt.sample.client;
    
    import com.smartgwt.client.data.DataSource;
    import com.smartgwt.client.data.SortSpecifier;
    import com.smartgwt.client.types.SortDirection;
    import com.smartgwt.client.widgets.grid.ListGrid;
    import com.smartgwt.client.widgets.grid.ListGridField;
    import com.smartgwt.client.widgets.layout.VLayout;
    import com.google.gwt.core.client.EntryPoint;
    
    public class Testcase implements EntryPoint {
    	@Override
    	public void onModuleLoad() {
    		VLayout vL = new VLayout() {
    			{
    				setWidth100();
    				setHeight100();
    				final DataSource testDS = DataSource.get("T_TEST3");
    
    				final ListGrid testLG = new ListGrid() {
    					{
    						setDataSource(testDS);
    //						setSort(new SortSpecifier[] { new SortSpecifier("DATUM", SortDirection.ASCENDING) });
    						setSortField("DATUM");
    //						setCanSort(false);
    						setCanEdit(true);
    						ListGridField datumLGF = new ListGridField("DATUM");
    //						setFields(datumLGF);
    						fetchData();
    					}
    				};
    				addMember(testLG);
    			}
    		};
    		vL.draw();
    	}
    }
    .ds.xml
    Code:
    <DataSource schema="testcase" dbName="Oracle" tableName="T_TEST" ID="T_TEST3" dataSourceVersion="1"
    	serverType="sql"
    >
    	<fields>
    		<field primaryKey="true" hidden="true" name="ID" type="sequence"></field>
    		<field name="DATUM" type="date"></field>
    	</fields>
    </DataSource>
    SQL (Oracle)
    Code:
    DROP TABLE t_test CASCADE CONSTRAINTS ;
    DROP SEQUENCE T_TEST_ID ;
     CREATE TABLE t_test
        (
          id     INTEGER NOT NULL,
          datum date
        ) ;
    CREATE SEQUENCE T_TEST_ID NOCACHE ORDER ;
    CREATE OR REPLACE TRIGGER t_test_BI BEFORE
       INSERT ON t_test FOR EACH ROW WHEN(NEW.id IS NULL) BEGIN
       SELECT T_TEST_ID.NEXTVAL INTO :NEW.id FROM DUAL;
    END;
    /
     insert into t_test
        (datum) values (sysdate-3);
     insert into t_test
        (datum) values (sysdate-2);
     insert into t_test
        (datum) values (sysdate-1);
     insert into t_test
        (datum) values (sysdate);
    commit ;
    Best regards,
    Blama

    #2
    2&3: not an error, setCanSort() means user cannot sort and sort icons are therefore not shown

    1: not an error, after a user makes an edit, the grid automatically unsort()s in order to avoid the just-edited record popping out of view

    Comment


      #3
      Hi Isomorphic,

      thanks for the fast answer. I think, then sth else is broken. Change to the following (int column added):

      SQL (Oracle):
      Code:
      DROP TABLE t_test CASCADE CONSTRAINTS ;
      DROP SEQUENCE T_TEST_ID ;
       CREATE TABLE t_test
          ( id INTEGER NOT NULL, num INTEGER, datum DATE
          ) ;
      CREATE SEQUENCE T_TEST_ID NOCACHE ORDER ;
      CREATE OR REPLACE TRIGGER t_test_BI BEFORE
         INSERT ON t_test FOR EACH ROW WHEN(NEW.id IS NULL) BEGIN
         SELECT T_TEST_ID.NEXTVAL INTO :NEW.id FROM DUAL;
      END;
      /
       INSERT INTO t_test
          (datum, num)
       SELECT sysdate - rownum, rownum FROM dual CONNECT BY level < 10;
      COMMIT ;
      Client Java:
      Code:
      package com.smartgwt.sample.client;
      
      import com.smartgwt.client.data.Criteria;
      import com.smartgwt.client.data.Criterion;
      import com.smartgwt.client.data.DataSource;
      import com.smartgwt.client.data.SortSpecifier;
      import com.smartgwt.client.types.OperatorId;
      import com.smartgwt.client.types.SortDirection;
      import com.smartgwt.client.widgets.grid.ListGrid;
      import com.smartgwt.client.widgets.grid.ListGridField;
      import com.smartgwt.client.widgets.layout.VLayout;
      import com.google.gwt.core.client.EntryPoint;
      
      public class Testcase implements EntryPoint {
      	@Override
      	public void onModuleLoad() {
      		VLayout vL = new VLayout() {
      			{
      				setWidth100();
      				setHeight100();
      				final DataSource testDS = DataSource.get("T_TEST3");
      
      				final ListGrid testLG = new ListGrid() {
      					{
      						setDataSource(testDS);
      //						Criterion crit = new Criterion("NUM", OperatorId.LESS_OR_EQUAL, 10);
      //						setCriteria(crit);
      						setSort(new SortSpecifier[] { new SortSpecifier("NUM", SortDirection.ASCENDING) });
      //						setSortField("TESTTEXT");
      //						setCanSort(false);
      //						setCanReorderRecords(true);
      						setCanEdit(true);
      						setCanFreezeFields(false);
      						setCanReorderFields(false);
      						setCanGroupBy(false);
      						ListGridField datumLGF = new ListGridField("DATUM");
      						ListGridField numLGF = new ListGridField("NUM");
      //						setFields(datumLGF, numLGF);
      //						getDataSource().setCacheAllData(true);
      //						fetchData(crit);
      						fetchData();
      					}
      				};
      				addMember(testLG);
      			}
      		};
      		vL.draw();
      	}
      }
      .ds.xml
      Code:
      <DataSource schema="testcase" dbName="Oracle" tableName="T_TEST" ID="T_TEST3" dataSourceVersion="1"
      	serverType="sql"
      >
      	<fields>
      		<field primaryKey="true" hidden="true" name="ID" type="sequence"></field>
      		<field name="DATUM" type="date"></field>
      		<field name="NUM" type="int"></field>
      	</fields>
      </DataSource>
      Note the following:
      Case 1:
      1) Load page, sorted by num (although sortdesc icon instead of sortasc icon used)
      2) Change num, grid still sorted (see your "1:")

      Case 2:
      1) uncomment "setFields(datumLGF, numLGF);"
      2) Load page, sorted by num (this time sortasc icon used)
      3) Change num, grid no longer sorted (see your "1:")

      From your post it seems that 2) is the correct behaviour.
      Whats the suggested practice for
      1: "On change of sorted column, keep sorted, keep showing sort icon?"
      2: 1+jump to entry?
      3: Sorted listgrid with sort icon shown where the user can't change sorting?

      Best regards,
      Blama

      Comment


        #4
        unsort() does not mean that the order is immediately scrambled, it means the sort icon disappears and order is no longer maintained.

        If you instead want to keep enforcing sort order even though it might pop the just-changed record out of view, you can call sort() from the DataChangedEvent.

        Comment


          #5
          Hi Isomorphic,

          thanks for the answer. Now I know what to do.
          IMO this stays open as a minor bug report:

          "Case 1:
          1) Load page, sorted by num (although sortdesc icon instead of sortasc icon used)
          2) Change num, grid still sorted (see your "1:")"

          In this case, the LG does sort on all subsequent edits and keeps the sort order, which is what I wanted, but not intended behaviour, if I understand you correct. Also, the displayed sort logo is wrong (desc/asc).

          Best regards,
          Blama

          Comment


            #6
            We attempted to reproduce that last minor bug report, but it seems to be working fine.

            Comment

            Working...
            X