Announcement

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

    Manipulating with SelectItem mutiple values

    Hi,

    being almost finished with my evaluation on SmartGWT, I would like to state, that at the moment it is a very well thought-out high-quality product.

    At first, I was thinking of choosing the Professional edition, but by the end I'm almost definite it must be at least the Power one. If you work with SQL(or any other) databases, real things, no doubt, start with Power edition.

    And here's the problem(which I guess in fact is "just my problem") I would like to be solved.

    Here's my code:
    Code:
        ...
        SelectItem selectItem = new SelectItem();
        selectItem.setMultipleAppearance(MultipleAppearance.PICKLIST);  
        selectItem.setMultiple(true);
        selectItem.setOptionDataSource(DataSource.get("role"));
        
        ListGridField rolesField = new ListGridField("roles", 620);
        rolesField.setEditorType(selectItem);
        ...
        grid.setFields(rolesField, ...);
    It works nice. When I click some "roles" cell withing my grid, I get multiple values(provided by selectItem) from option datasource to choose from, by selecting check boxes to the left side of the proposed values.

    The values are selected, as it is shown in "setdata.png" attachment and after the saving is made they are successfuly stored in the database and shown in appropriate cells.

    When I click back again at this "roles" cell(which correctly displays the saved values), and the selectItem is shown again, none of it's checkbox selections that were previously set "by hand" remain active. It can be seen in "getdata.png".

    I guess, it could be done programmatically with selectItem object, by setting the appropriate checkboxes according to the aggregated values in the cell, and if it is so, which methods and events should be involved in this process? Having browsed all the forum, and having done some tries just couldn't find the solution.

    Thanks!
    Attached Files

    #2
    The SQLDataSource doesn't have automatic support for storing multiple values within a single column, so what you're seeing is basically the toString() of a List of Strings being saved to the column, and that same String being returned to the client.

    You could compensate for this in a DMI (combining the string values with some kind of separator on add/update, and splitting them on fetch) or even using dataSourceField.customSelectExpression et al. Or you could switch to storing each value as its own row in a separate table (more typical for SQL, and allows joins involving these values).

    Comment


      #3
      Thanks for the quick answer!

      I don't feel any discomfort in getting the result in a "toString()" style. Yes, I can manage it by splitting the string.

      But, what confuses me is how to keep the proper reflection of the result within the SelectItem area(when the user clicks back the cell and gets SelectItem expanded), i.e. setting it's appropriate check boxes to "true".

      I could think of it as of the following example, for instance:
      Code:
          ...
          selectItem.addClickHandler(new ClickHandler() {
            @Override
            public void onClick(ClickEvent event) {
              // !!! perform actions to set appropriate selectItem's check boxes to "true" depending on the splitting of the "toString()" result 
            }
          });
          ...
      And in this case I would wonder what actions should be done with SelectItem at comment place.

      Or maybe I didn't get right your answer?

      Comment


        #4
        At last I got it working.

        In my DMI handler in "fetch" method I replaced the "toString()" value which is returned by default, with String[] value by splitting the source, and applying the response.setFieldValue(<field name>, <String[]>) method.

        In my client code I've done the following:
        Code:
            rolesField.addCellSavedHandler(new CellSavedHandler() {
              @Override
              public void onCellSaved(CellSavedEvent event) {
                grid.invalidateCache();
                grid.fetchData(grid.getCriteria());
              }
            });
        I would also like to wish Isomorphic to write more practical documentation on SmartGWT such as tutorials and typical code samples.

        That's where the disbalance is, compared to it's excellent design. People usually don't like wasting time trying to resolve insignificant not well-documented things.

        Having friendly documentation matters a lot more than just 50% of such product success.

        Thanks!

        Comment


          #5
          You don't need to do anything client-side and your solution isn't as good the way you've done it (it fetches data unnecessarily). Instead, use a DMI on add and update to split the data server side, before the client sees it.

          We have more samples by far than any similar product - the reason there's no sample for this is that we don't really recommend this approach. When using SQL/Relational storage, it's more typical to create a table for storing multiple values than to store them in a single column, again because only when they are in a separate table can they be conveniently used in SQL joins.

          Comment

          Working...
          X