Announcement

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

    how to set initialData on treeGrid

    Hello,

    Using
    ** Smart GWT Forum
    I am using the following
    SmartClient Version: v8.3p_2013-04-19/PowerEdition Deployment (built 2013-04-19)


    GWT 2.5.1

    I have read the documentation and am starting a new thread with the specific related to TreeGrid.

    I see that the initial data takes an array of TreeNodes. I would like to get the data from mysql. I tried using a ResultSet, but it did not seem to get all the data (by design per documentation of Result Set). What is the correct way to get all the data on a request? So I can set the initial data in my tree grid?

    Evan

    #2
    Take 1

    Hello,

    Here is my current try. I need to set the fetch operation, as I have some custom sql. Where do I do a "setFetchOperation" in the code below? There is no such method on ds ...

    Evan


    private void myFetchDataTreeGrid() {
    String strSearchText = textItem.getValueAsString();
    final AdvancedCriteria crit = new AdvancedCriteria(new Criterion("searchsyn", currentOperatorId, strSearchText));
    final DataSource ds = DataSource.get(DataSourceInfo.PARENTS_SEARCH_ENITITES_DATASOURCE_MYSQL);
    DSRequest request = new DSRequest();
    ds.fetchData(crit, new DSCallback() {
    @Override
    public void execute(DSResponse response, Object rawData, DSRequest request)
    {
    final ResultSet resultset = new ResultSet();
    resultset.setDataSource(ds);
    resultset.setCriteria(crit);
    resultset.setFetchMode(FetchMode.LOCAL);
    int ilen = response.getTotalRows();
    resultset.setInitialLength(ilen);

    Record[] responseData = response.getData();
    Record[] initialData = new Record[response.getEndRow()+1];
    for (int i = 0; i <= response.getEndRow(); i++) {
    if (i < response.getStartRow()) initialData[i] = null;
    else initialData[i] = responseData[i-response.getStartRow()];
    }
    resultset.setInitialData(initialData);
    resultset.setInitialSort(request.getSortBy());
    treeGrid.setData(resultset);
    showGrid();
    }
    }, request);

    }

    Comment


      #3
      bindings

      Ok my last post till you catch up and point me where to go - I promise :-).

      Setting the fetch operation is the goal, tried the following. But clearly wrong as says can't set operation binding after component created. Still looked like the right idea.

      Evan

      final DataSource ds = DataSource.get(DataSourceInfo.PARENTS_SEARCH_ENITITES_DATASOURCE_MYSQL);
      OperationBinding obind = new OperationBinding();
      obind.setOperationId(eCurrentSearchOnType.getOpIDSearchEntities());
      ds.setOperationBindings(obind);

      Comment


        #4
        hmm

        Reading the doc (see below) indicates this is how to set the operationId. But I get an error (see below), so what did I miss?

        final DataSource ds = DataSource.get(DataSourceInfo.PARENTS_SEARCH_ENITITES_DATASOURCE_MYSQL);
        // Documentation says : Note that if you manually invoke a DataSource operation, you can also specify operationId via the
        // requestProperties parameter.
        DSRequest request = new DSRequest();
        request.setOperationId(eCurrentSearchOnType.getOpIDSearchEntities());
        ds.setRequestProperties(request);


        Gives me the error

        java.lang.IllegalStateException: Cannot change configuration property 'requestProperties' to [object Object] after the component has been created.

        Comment


          #5
          progress

          Hello,

          Ok making progress. Though I can't set the request properties on the data source, I can pass it into the fetch.
          So I "think" data comes back as the array is set. And as I said "local" I think all the data must come back.

          And this code now executes to the end. But when I show my tree it does not contain any data! So where did I go wrong now?

          Evan

          // Smart GWT Note:
          // Note that if you manually invoke a DataSource operation, you can also specify operationId via the
          // requestProperties parameter.
          private void myFetchDataTreeGrid() {
          String strSearchText = textItem.getValueAsString();
          final AdvancedCriteria crit = new AdvancedCriteria(new Criterion("searchsyn", currentOperatorId, strSearchText));
          final DataSource ds = DataSource.get(DataSourceInfo.PARENTS_SEARCH_ENITITES_DATASOURCE_MYSQL);
          DSRequest request = new DSRequest();
          request.setOperationId(eCurrentSearchOnType.getOpIDSearchEntities());
          DSCallback callback = new DSCallback() {
          @Override
          public void execute(DSResponse response, Object rawData, DSRequest request)
          {
          final ResultSet resultset = new ResultSet();
          resultset.setDataSource(ds);
          resultset.setCriteria(crit);
          resultset.setFetchMode(FetchMode.LOCAL);
          Record[] responseData = response.getData();
          int ilen = responseData.length;
          resultset.setInitialLength(ilen);
          Record[] initialData = new Record[responseData.length];
          for (int i = 0; i < ilen; i++) {
          initialData[i] = responseData[i];
          }
          resultset.setInitialData(initialData);
          treeGrid.setData(resultset);
          showGrid();
          }
          };
          ds.fetchData(crit, callback, request);
          }

          Comment


            #6
            hmm

            Betting it is my use of "setData" and not "setInitialData". So will see about making my array of treenodes.

            Evan

            Comment


              #7
              initialData

              Hello,

              Well initialData can only be set before drawn. And I am reusing my treegrid.

              So trying to setData, which I would think would still render the tree.

              Below is my "code" along with a print out of the nodes I am adding. I would think it would show the tree. Seems well formed to me ...

              Evan


              From the client print out to console
              === 2013-05-17 09:14:59,522 [l0-2] INFO Compression - /winter/sc/IDACall: 1086 -> 385 bytes
              * Digestive System Diseases, id = 94228, parentid = 0
              * Gastrointestinal Diseases, id = 158453, parentid = 94228
              * Gastroenteritis, id = 284744, parentid = 158453
              * Inflammatory Bowel Diseases, id = 284951, parentid = 285787
              * Inflammatory Bowel Diseases, id = 284952, parentid = 284744
              * Intestinal Diseases, id = 285787, parentid = 158453


              And some code
              // Smart GWT Note:
              // Note that if you manually invoke a DataSource operation, you can also specify operationId via the
              // requestProperties parameter.
              private void myFetchDataTreeGrid() {
              String strSearchText = textItem.getValueAsString();
              final AdvancedCriteria crit = new AdvancedCriteria(new Criterion("searchsyn", currentOperatorId, strSearchText));
              final DataSource ds = DataSource.get(DataSourceInfo.PARENTS_SEARCH_ENITITES_DATASOURCE_MYSQL);
              DSRequest request = new DSRequest();
              request.setOperationId(eCurrentSearchOnType.getOpIDSearchEntities());
              DSCallback callback = new DSCallback() {
              @Override
              public void execute(DSResponse response, Object rawData, DSRequest request)
              {
              Record[] responseData = response.getData();
              int ilen = responseData.length;
              boolean bAllDataLoaded = true;
              // +1 for the root, set after loop exits
              TreeNode treenodes[] = new TreeNode[ilen + 1];
              int i = 0;
              for (; i < ilen; i++) {
              Record r = responseData[i];
              // new node arrived so copy over
              TreeNode n = new TreeNode();
              String strTitle = r.getAttributeAsString("entsyn");
              String parentid = r.getAttributeAsString("parentkey");
              String id = r.getAttributeAsString("entkey");
              System.out.println("* " + strTitle + ", id = " + id + ", parentid = " + parentid);
              n.setID(id);
              n.setParentID(parentid);
              n.setTitle(strTitle);
              treenodes[i] = n;
              }
              treenodes[i] = getRootTreeNode();
              treeGrid.setData(treenodes);
              showGrid();
              }
              };
              ds.fetchData(crit, callback, request);
              }

              private TreeNode getRootTreeNode() {
              TreeNode n = new TreeNode();
              n.setID("0");
              n.setParentID("0");
              n.setTitle("root");
              return n;
              }

              Comment


                #8
                sooo close

                Hello,

                So my treegrid now crashes when it is about to Display.

                I think I now have "initialdata" right. I had to modify my code to create a new tree grid for each time. And add it to the window.

                However, now I get a
                == 2013-05-17 10:20:36,486 [l0-6] INFO Compression - /winter/sc/IDACall: 1086 -> 385 bytes
                Uncaught JavaScript exception [TypeError: this.getDataSource(...) is undefined] in http://127.0.0.1:8888/winter/sc/modules/ISC_DataBinding.js, line 1463


                Not sure how to debug this.

                I figure this is due to the auto load of the demand on the initial creation. Which was not what I wanted.

                I have attached my code, trimmed down as the upload attach feature for the forum does not like larger files.

                Thanks for all the help with this. It is very important to us to get this tree working. And as you can see I am working away at it.

                Thanks,
                Evan
                Attached Files

                Comment


                  #9
                  more progress

                  Hello,

                  I can now setInitialData on my listtree, and it shows up !!
                  However, the tree is "flat".

                  I am betting that as I am not using a result tree I have not
                  indicate my .setModelType(TreeModelType.PARENT).

                  How do I set the model type when I just use setinitialdata?

                  Thanks,
                  Evan

                  Comment


                    #10
                    treeGrid.setDataProperties(resultTreeProperties)

                    this looks likely

                    Comment


                      #11
                      To retrieve data from the server for programmatic use (like setting initialData), just use DataSource.fetchData(). No need for a ResultSet or anything like that.

                      You do not need to set modelType to parent. You just have to have a DataSource that has correct properties set for tree data binding (see Tree DataBinding Overview), and then of course the data itself must have correct values for the idField and parentIdField.

                      Bigger picture however, you seem to be trying to set initialData due to your struggles in this thread, but this is not necessary either. We will respond in the other thread.

                      Comment

                      Working...
                      X