Announcement

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

    How to use listgrid expansion mode editor ?

    Thats my question ? How should I use the list grid expansionmode editor ?

    Code:
    		listGrid.setCanExpandRecords(true);
    		listGrid.setExpansionMode(ExpansionMode.DETAILS);
    How should I submit the form ?

    How should I get the values ?

    Thanks!

    #2
    I think you should start with http://www.smartclient.com/smartgwt/showcase/#grid_expanding_details, the DETAILS just provide the rest of the listgrid record that isn't a field in the table already. So not sure what your really asking about?

    Comment


      #3
      Yes, But what if i want to edit those records that are not shown on the table (the ones in the expanded table) ?

      Comment


        #4
        Then you just take a look at: http://www.smartclient.com/smartgwt/showcase/#grid_nested_form, it isn't any different in handling the form

        Comment


          #5
          I tried using this example with rpc datasource, and it fails.

          This error is shown when I save the form

          java.lang.ClassCastException: com.smartgwt.client.widgets.form.DynamicForm cannot be cast to com.smartgwt.client.widgets.grid.ListGrid
          at datasource.example.client.TestDataSource.executeUp date(TestDataSource.java:98).

          Comment


            #6
            Well its custom code, so assuming this works on a standard form, post your code where the exception if occuring.

            Comment


              #7
              I am using the GwtRpcDataSource

              My datasource is the following

              Code:
              public class TestDataSource  extends GwtRpcDataSource {
              
                  public TestDataSource () {
                      DataSourceField field;
                      field = new DataSourceIntegerField ("id", "ID");
                      field.setPrimaryKey (true);
                      field.setRequired (false);
                      addField (field);
                      field = new DataSourceTextField ("name", "NAME");
                      field.setRequired (true);
                      addField (field);
                      field = new DataSourceDateField ("date", "DATE");
                      field.setRequired (false);
                      addField (field);
                  }
              
                  @Override
                  protected void executeFetch (final String requestId, final DSRequest request, final DSResponse response) {
              TestServiceAsync service = GWT.create (TestService.class);
                      service.fetch (new AsyncCallback<List<TestRecord>> () {
                          public void onFailure (Throwable caught) {
                              response.setStatus (RPCResponse.STATUS_FAILURE);
                              processResponse (requestId, response);
                          }
                          public void onSuccess (List<TestRecord> result) {
                              ListGridRecord[] list = new ListGridRecord[result.size ()];
                              for (int i = 0; i < list.length; i++) {
                                  ListGridRecord record = new ListGridRecord ();
                                  copyValues (result.get (i), record);
                                  list[i] = record;
                              }
                              response.setData (list);
                              processResponse (requestId, response);
                          }
                      });
                  }
              
                  @Override
                  protected void executeAdd (final String requestId, final DSRequest request, final DSResponse response) {
                     JavaScriptObject data = request.getData ();
                      ListGridRecord rec = new ListGridRecord (data);
                      TestRecord testRec = new TestRecord ();
                      copyValues (rec, testRec);
                      TestServiceAsync service = GWT.create (TestService.class);
                      service.add (testRec, new AsyncCallback<TestRecord> () {
                          public void onFailure (Throwable caught) {
                              response.setStatus (RPCResponse.STATUS_FAILURE);
                              processResponse (requestId, response);
                          }
                          public void onSuccess (TestRecord result) {
                              ListGridRecord[] list = new ListGridRecord[1];
                              ListGridRecord newRec = new ListGridRecord ();
                              copyValues (result, newRec);
                              list[0] = newRec;
                              response.setData (list);
                              processResponse (requestId, response);
                          }
                      });
                  }
              
                  @Override
                  protected void executeUpdate (final String requestId, final DSRequest request, final DSResponse response) {
                      JavaScriptObject data = request.getData ();
                      ListGridRecord rec = new ListGridRecord (data);
                      ListGrid grid = (ListGrid) Canvas.getById (request.getComponentId ());
                       int index = grid.getRecordIndex (rec);
                      rec = (ListGridRecord) grid.getEditedRecord (index);
                      TestRecord testRec = new TestRecord ();
                      copyValues (rec, testRec);
                      TestServiceAsync service = GWT.create (TestService.class);
                      service.update (testRec, new AsyncCallback<TestRecord> () {
                          public void onFailure (Throwable caught) {
                              response.setStatus (RPCResponse.STATUS_FAILURE);
                              processResponse (requestId, response);
                          }
                          public void onSuccess (TestRecord result) {
                              ListGridRecord[] list = new ListGridRecord[1];
                              ListGridRecord updRec = new ListGridRecord ();
                              copyValues (result, updRec);
                              list[0] = updRec;
                              response.setData (list);
                              processResponse (requestId, response);
                          }
                      });
                  }
              
                  @Override
                  protected void executeRemove (final String requestId, final DSRequest request, final DSResponse response) {
                      JavaScriptObject data = request.getData ();
                      final ListGridRecord rec = new ListGridRecord (data);
                      TestRecord testRec = new TestRecord ();
                      copyValues (rec, testRec);
                      TestServiceAsync service = GWT.create (TestService.class);
                      service.remove (testRec, new AsyncCallback () {
                          public void onFailure (Throwable caught) {
                              response.setStatus (RPCResponse.STATUS_FAILURE);
                              processResponse (requestId, response);
                          }
                          public void onSuccess (Object result) {
                              ListGridRecord[] list = new ListGridRecord[1];
                              list[0] = rec;
                              response.setData (list);
                              processResponse (requestId, response);
                          }
              
                      });
                  }
              
                  private static void copyValues (ListGridRecord from, TestRecord to) {
                      to.setId (from.getAttributeAsInt ("id"));
                      to.setName (from.getAttributeAsString ("name"));
                      to.setDate (from.getAttributeAsDate ("date"));
                  }
              
                  private static void copyValues (TestRecord from, ListGridRecord to) {
                      to.setAttribute ("id", from.getId ());
                      to.setAttribute ("name", from.getName ());
                      to.setAttribute ("date", from.getDate ());
                  }
              }
              And my entry point class :
              Code:
              public class ProbandoDataSource implements EntryPoint {
              
              	public void onModuleLoad() {
              
              		final DataSource dataSource = new TestDataSource();
              
              		final ListGrid listGrid = new ListGrid() {
              			@Override
              			protected Canvas getExpansionComponent(final ListGridRecord record) {
              
              				final ListGrid grid = this;
              				VLayout layout = new VLayout(2);
              				
              				final DynamicForm df = new DynamicForm();
              				df.setNumCols(2);
              				df.setDataSource(dataSource);
              
              				df.addDrawHandler(new DrawHandler() {
              					public void onDraw(DrawEvent event) {
              						df.editRecord(record);
              					}
              				});
              
              				IButton saveButton = new IButton("Save");
              				saveButton.addClickHandler(new ClickHandler() {
              					public void onClick(ClickEvent event) {
              						 df.saveData();
              //I m using this to  update the record on the grid ( the view)
              	record.setAttribute("id", (Integer) df.getValue("id"));
              	record.setAttribute("name", (String) df.getValue("name"));
              	record.setAttribute("date", (Date) df.getValue("date"));
              
              //dataSource.updateData(record); fails
              // grid.updateData(record); fails		
              			}
              				});
              
              				IButton cancelButton = new IButton("Done");
              				cancelButton.addClickHandler(new ClickHandler() {
              					public void onClick(ClickEvent event) {
              						grid.collapseRecord(record);
              					}
              				});
              
              				HLayout hLayout = new HLayout(10);
              				hLayout.addMember(saveButton);
              				hLayout.addMember(cancelButton);
              
              				layout.addMember(df);
              				layout.addMember(hLayout);
              				return layout;
              			}
              		};
                              listGrid.setCanExpandRecords(true);
              		listGrid.setAutoFetchData(true);
              		listGrid.setDataSource(dataSource);
              
              		ListGridField itemNameField = new ListGridField("name");
              		ListGridField skuField = new ListGridField("id");
              
              		listGrid.setFields(itemNameField, skuField);
              
              		listGrid.draw();
              	}
              
              }
              My problem is that when I am press the save button this error is shown :


              Java.lang.ClassCastException: com.smartgwt.client.widgets.form.DynamicForm cannot be cast to com.smartgwt.client.widgets.grid.ListGrid
              at datasource.example.client.TestDataSource.executeUp date(TestDataSource.java:98).

              When I tried with

              Code:
              dataSource.updateData(record); grid.updateData(record);

              This error is shown

              Java.lang.NullPointerException: null
              at datasource.example.client.TestDataSource.executeUp date(TestDataSource.java:100)

              Any suggestion ?

              Comment


                #8
                This is very interesting.

                I am willing to customize the display of expansion with some static strings in the middle, just like in nested form, I'd like to put a nested canvas with buttons and images. it would be perfect.

                So considering bumping this topic to get an answer as well as some info on my ideas.

                Cheers,

                EJ
                Last edited by joppert; 20 Jan 2011, 13:50.

                Comment


                  #9
                  [del]How can we define Format string to DD-MM-YYYY or something like German or other locales?[/del]

                  I was able to make this work on the regarding topic
                  http://forums.smartclient.com/showpo...90&postcount=5


                  Cheers,

                  EJ
                  Last edited by joppert; 24 Jan 2011, 02:16.

                  Comment

                  Working...
                  X