Announcement

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

    DataSource question on passing in the "old" fields

    Hi,

    I stumbled on the following in the javaDoc for setDataSource on ListGrid (complete javadoc below):

    When binding to a new DataSource, if the component has any existing "fields" or has a dataset,
    these will be discarded by default, since it is assumed the new DataSource may represent a completely unrelated set of objects.
    If the old "fields" are still relevant, pass them to setDataSource().

    My old fields are still relevant, so how do you pass in these "fields" to the setDataSource? I can't seem to find any API that allows this?

    Originally posted by JavaDoc
    void com.smartgwt.client.widgets.grid.ListGrid.setDataSource(DataSource dataSource)

    The DataSource that this component should bind to for default fields and for performing com.smartgwt.client.data.DSRequest.

    Can be specified as either a DataSource instance or the String ID of a DataSource. Bind to a new DataSource.

    Like passing the "dataSource" property on creation, binding to a DataSource means that the component will use the DataSource to provide default data for its fields.

    When binding to a new DataSource, if the component has any existing "fields" or has a dataset, these will be discarded by default, since it is assumed the new DataSource may represent a completely unrelated set of objects. If the old "fields" are still relevant, pass them to setDataSource().

    #2
    Just call setFields() after calling setDataSource().

    Comment


      #3
      I too just had this question. Can you update the docs to say "setFields", not "setDataSource"?

      Comment


        #4
        We plan to actually add a signature setDataSource(dataSource, fields) for each DBC.

        Comment


          #5
          Even better! :)

          I have run across a snag with setting Fields --
          Code:
          form.setFields(field2, spacer1, operation2, spacer2, value2);
          and later (to set the form's datasource to the grid's)...
          Code:
          FormItem[] f = form.getFields();
          form.setDataSource(grid.getDataSource());
          if (f.length > 0)
          	form.setFields(f);
          But I get this...
          Code:
          WARN(x5) :DynamicForm:isc_DynamicForm_4:destroyed FormItem passed to setItems()/addItem(): FormItems cannot be re-used with different DynamicForms
          This seem like a bug because the formItems in the UI are permanently disabled. So for now, I check if there are existing Fields before setting the datasource:
          Code:
          if (form.getFields().length == 0 &&
          	form.getDataSource() == null && 
          	grid.getDataSource() != null) {
          		form.setDataSource(grid.getDataSource());
          }
          Is there a way to avoid this issue?

          Comment


            #6
            It's not a bug - "FormItems cannot be re-used with different DynamicForms" as the log message says, but to clarify, you also can't re-use the FormItem with the same form after wiping out all of it's fields. You should instead create a method that returns the FormItems you want to apply to the DynamicForm and use it in both circumstances.

            Comment


              #7
              This is very helpful to know - thanks.
              Last edited by bootz15; 6 Jun 2011, 06:00.

              Comment


                #8
                Originally posted by bootz15
                I too just had this question. Can you update the docs to say "setFields", not "setDataSource"?
                The same applies even to SmartGwt 2.5.

                Cheers
                Davide

                Comment

                Working...
                X