Announcement

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

    How to add records to a listgrid without call startEditingNew and without server trip

    Hello,

    I evaluating the smartgwt enterprise edition 3.1d and try to achieve the following:

    - adding several records to a ListGrid without contacting the server (the record is created by the program when a drop event occurs)
    - mark some records for removing (optional)
    - after triggering the save button I want to commit all the work to the server
    - all ListGridFields are not editable, that's why startEditingNew(Record) doesn't work

    If one ListGridField is editable everything works like expected.
    I also tried to call ListGrid:addData(record) but this immediatly calls the server to add the data.

    Is there a way I can schedule these adds?

    #2
    startEditingNew() does not require all fields to be editable. See the ListGrid Editing Overview, and see also canEditCell().

    Comment


      #3
      Hello,

      as I stated in the first post, I know that it works with at least one field editable. But my usecase is, that there is no field editable.

      Comment


        #4
        Sorry, misread you.

        Consider using a clientOnly:true DataSource so that you can addData() without server contact.

        Another approach is providing a RecordList as the data model, which you can also modify locally without server contact.

        Comment


          #5
          Originally posted by Isomorphic View Post
          Another approach is providing a RecordList as the data model, which you can also modify locally without server contact.
          Can I use this RecordList combined in local and server mode?

          Comment


            #6
            Not sure what this means, but you can get a RecordList in the callback of DataSource.fetchData() and add Records to it, which creates a combination of server-fetched data and locally added Records.

            Comment


              #7
              Ok, now I have the RecordList of the fetch response. But after adding a new record, this record isn't drawn in the ListGrid. Am I missing something?

              Comment


                #8
                Can you show your code for getting the RecordList, modifying it and providing it to the ListGrid?

                Comment


                  #9
                  I missed to set the RecordList as data for the Listgrid...

                  now my code ist like this

                  Code:
                  getListGrid().fetchData(criteria, new DSCallback() {
                  				@Override
                  				public void execute(DSResponse response, Object rawData, DSRequest request) {
                  					recordList = response.getDataAsRecordList();
                  				}
                  			});
                  after creating some record:

                  Code:
                  recordList.add(targetRecord);	
                  getListGrid().setData(recordList);
                  after editing:

                  Code:
                  getListGrid().saveAllEdits();
                  Now this doesn't work, b/c the ResultList is decoupled from the datasource, am I right?

                  Comment


                    #10
                    Right, at this point, the ListGrid is not tracking your new records as edits (since they are not edits). But you can track them separately, and by calling startQueue() before calling saveAllEdits(), can combine calls to DataSource.addData() in the same queue as edits made to existing records in the ListGrid.

                    Comment


                      #11
                      Originally posted by Isomorphic View Post
                      you can get a RecordList in the callback of DataSource.fetchData() and add Records to it, which creates a combination of server-fetched data and locally added Records.
                      As it turns out, I always need to hijack the DS-Fetch Operation to get a RecordList from the response to set this to the ListGrid. Is there also a way to intercept the Fetch-Operation for the buildin FilterEditor? I've got the usecase that some filetring is enabled (fetching remote data) and the User should add new Records tho the ResultSet. If i use the result set as follow:

                      Code:
                      	public void onModuleLoad() {
                      		DataSource ds = new DataSource();
                      		ds.setFields(new DataSourceField("f1", FieldType.TEXT));
                      		ds.setClientOnly(true);
                      
                      		final ListGrid lg = new ListGrid();
                      
                      		lg.setFields(new ListGridField("f1"));
                      		lg.setDataSource(ds);
                      		lg.setAutoFetchData(true);
                      
                      		ToolStrip strip = new ToolStrip();
                      		ToolStripButton add = new ToolStripButton("add");
                      		add.addClickHandler(new com.smartgwt.client.widgets.events.ClickHandler() {
                      			@Override
                      			public void onClick(ClickEvent event) {
                      				lg.getRecordList().add(new Record() {
                      					{
                      						setAttribute("f1", "foo");
                      					}
                      				});
                      			}
                      		});
                      		strip.addButton(add);
                      		lg.setGridComponents(ListGridComponent.HEADER, ListGridComponent.BODY, strip);
                      		lg.draw();
                      	}
                      I always get this Exception:

                      Code:
                      com.google.gwt.event.shared.UmbrellaException: Exception caught: (TypeError) @com.smartgwt.client.data.RecordList::add(Lcom/smartgwt/client/data/Record;)([Java object: test.EntryPoint$1$1@1023866887]): this.addAt is not a function
                      	at com.google.gwt.event.shared.HandlerManager.fireEvent(HandlerManager.java:129)
                      	at com.smartgwt.client.widgets.BaseWidget.fireEvent(BaseWidget.java:71)
                      	at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
                      	at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
                      	at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
                      	at java.lang.reflect.Method.invoke(Method.java:597)
                      	at com.google.gwt.dev.shell.MethodAdaptor.invoke(MethodAdaptor.java:103)
                      	at com.google.gwt.dev.shell.MethodDispatch.invoke(MethodDispatch.java:71)
                      	at com.google.gwt.dev.shell.OophmSessionHandler.invoke(OophmSessionHandler.java:172)
                      	at com.google.gwt.dev.shell.BrowserChannelServer.reactToMessagesWhileWaitingForReturn(BrowserChannelServer.java:338)
                      	at com.google.gwt.dev.shell.BrowserChannelServer.invokeJavascript(BrowserChannelServer.java:219)
                      	at com.google.gwt.dev.shell.ModuleSpaceOOPHM.doInvoke(ModuleSpaceOOPHM.java:136)
                      	at com.google.gwt.dev.shell.ModuleSpace.invokeNative(ModuleSpace.java:570)
                      	at com.google.gwt.dev.shell.ModuleSpace.invokeNativeObject(ModuleSpace.java:278)
                      	at com.google.gwt.dev.shell.JavaScriptHost.invokeNativeObject(JavaScriptHost.java:91)
                      	at com.google.gwt.core.client.impl.Impl.apply(Impl.java)
                      	at com.google.gwt.core.client.impl.Impl.entry0(Impl.java:242)
                      	at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
                      	at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
                      	at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
                      	at java.lang.reflect.Method.invoke(Method.java:597)
                      	at com.google.gwt.dev.shell.MethodAdaptor.invoke(MethodAdaptor.java:103)
                      	at com.google.gwt.dev.shell.MethodDispatch.invoke(MethodDispatch.java:71)
                      	at com.google.gwt.dev.shell.OophmSessionHandler.invoke(OophmSessionHandler.java:172)
                      	at com.google.gwt.dev.shell.BrowserChannelServer.reactToMessages(BrowserChannelServer.java:293)
                      	at com.google.gwt.dev.shell.BrowserChannelServer.processConnection(BrowserChannelServer.java:547)
                      	at com.google.gwt.dev.shell.BrowserChannelServer.run(BrowserChannelServer.java:364)
                      	at java.lang.Thread.run(Thread.java:662)
                      I also tried to use a DataArrivedHandler but there is the same exception shown above.

                      Can you please also tell me, if it is possible to get records which are added to the ResultSet to be marked like they where added via startEditingNew (this nice blue showing the user that the date is not yet stored)?

                      Thanks
                      Andreas

                      Comment


                        #12
                        Don't know what you mean by "hijack" but what you want to do is call *DataSource.fetchData()* (*not* ListGrid.fetchData()), then modify the RecordList you receivers the callback before applying it via ListGrid.setData().

                        No, Records that you add via recordList.add() cannot be made into unsaved Records - there doesn't seem to be a purpose to this.

                        Comment


                          #13
                          The RecordSet will be overwritten as soon the user uses the FilterEditor of the Listgrid, isn't it? If I understand you right, I can't use ListGridFeatures like autoFetch, filtering, fetchingReleatedData with this aproach?

                          Comment


                            #14
                            If you form a ResultSet with your mixture of server-fetched and client-provided data, using the FilterEditor, sorting, etc will work normally.

                            autoFetchData should not be set if you are manually fetching data and applying it via setData().

                            Comment

                            Working...
                            X