Announcement

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

    Can't add a colum with list items to a grid.

    Hello, I can't handle with such an easy operation :-(
    I'm using smartgwt 4.1

    I need to create a grid with three columns.
    In the first and the second column I need to keep Id and lable of an entity from database. I want to receive this data by Request.

    In the third row I want to keep a ListBox with 3 options - "no","R","RW"

    I'm trying to do it this way:

    Code:
      ListGrid rightsGrid = new ListGrid();
    ....
    
    ListGridField rdsUnique = new ListGridField("uniqueId", "uniqueId");
            rdsUnique.setHidden(true);
    
            ListGridField rdsLabel = new ListGridField("label", rolesDirNLS.objectName());
            rdsLabel.setAutoFitWidthApproach(AutoFitWidthApproach.BOTH);
            rdsLabel.setCanEdit(false);
    
            ListGridField rdsRight = new ListGridField("right", rolesDirNLS.right());
    
    
            ResultSet resultSet = new ResultSet();
    
            rightsGrid.setShowAllRecords(true);
            rightsGrid.setAlwaysShowEditors(true);
            rightsGrid.setFields(rdsUnique, rdsLabel, rdsRight);
            rdsRight.setAutoFitWidthApproach(AutoFitWidthApproach.TITLE);
            rightsGrid.setCanEdit(true);
            rightsGrid.setEditEvent(ListGridEditEvent.CLICK);
    
            SelectItem rightSelectItem = new SelectItem();
            rightSelectItem.setValueMap("NO", "R", "RW");
    
    
            rightSelectItem.setEmptyDisplayValue(rolesDirNLS.no());
            rightSelectItem.setDefaultValue(rolesDirNLS.no());
            rightSelectItem.setAddUnknownValues(false);
            rdsRight.setEditorType(rightSelectItem);
            
                RequestBuilder getObjects = new CustomRequestBuilder(RequestBuilder.GET, common.prefix() + "/object_type/");
                getObjects.setCallback(new RequestCallback() {
                    @Override
                    public void onResponseReceived(Request request, Response response) {
                        if (response.getStatusCode() == 200) {
                            JSONArray objectsArray = JSONParser.parseStrict(response.getText()).isArray();
                            for (int i = 0; i < objectsArray.size(); i++) {
                                JSONObject Object = objectsArray.get(i).isObject();
                                if (Object != null) {
                                    ListGridRecord record = new ListGridRecord();
                                    record.setAttribute("uniqueId", Object.get("uniqueId").isString().stringValue());
                                    record.setAttribute("label", Object.get("label").isString().stringValue());
                                    rightsGrid.addData(record);
                                }
                            }
                        } else {
                            SC.warn(notifications.rest_on_error());
                        }
                    }
    
                    @Override
                    public void onError(Request request, Throwable throwable) {
                        SC.warn(throwable.getMessage());
                    }
                });
                try {
                    getObjects.send();
                } catch (RequestException e) {
                    e.printStackTrace();
                }
    it shows me a grid with a listbox. But when I change selections in two rows and try to iterate grid to get this rows - i get only first value.

    Guys, I can't understand what I'm doing wrong. Please, help me with this rather easy task

    #2
    I tried to use setEditorProperties method instead of setEditorType cause it is deprecated and changed setting values to setting value map, but it didn't help

    Code:
    SelectItem rightSelectItem = new SelectItem("right");
            LinkedHashMap<String,String> map = new LinkedHashMap<>();
            map.put("NO",rolesDirNLS.no());
            map.put("R","R");
            map.put("RW","RW");
    
            rightSelectItem.setValueMap(map);        
    
            if (uniqueId.equals("null")) {
                rightSelectItem.setEmptyDisplayValue(rolesDirNLS.no());
                rightSelectItem.setDefaultValue(rolesDirNLS.no());
            }
            rightSelectItem.setAddUnknownValues(false);
            rdsRight.setEditorProperties(rightSelectItem);

    Comment


      #3
      Guys, still have this problem. Can anyone help me? May be I can't figure out some very simple thing?

      Comment


        #4
        I don't think you're getting any responses because of the confusing nature of your post. So you created a list grid, and you see it populating correctly? Yet when you try to obtain the values you've changed within the list grid you're not able to see more than one record? The code you posted is the code to create the list grid, not to obtain data from it, so if that's the area you're having trouble with it would make sense to post that code, yes? Screenshots would also be helpful if you're seeing something other than what you expect.

        Comment


          #5
          Originally posted by beckyo View Post
          I don't think you're getting any responses because of the confusing nature of your post. So you created a list grid, and you see it populating correctly? Yet when you try to obtain the values you've changed within the list grid you're not able to see more than one record? The code you posted is the code to create the list grid, not to obtain data from it, so if that's the area you're having trouble with it would make sense to post that code, yes? Screenshots would also be helpful if you're seeing something other than what you expect.
          Hello, beckyo

          Oh, ofcourse. Here is the code.

          Code:
          int i = 0;
          for (Record record : rightsGrid.getRecords()) {
          if(record.getAttribute("right")!=null){
                if (record.getAttribute("right").equals("R") ||    record.getAttribute("right").equals("RW")) {
          
          JSONObject roleObject = new JSONObject();
          
          JSONObject objectTypeJSON = new JSONObject();
          roleObject.put("permission", new JSONString(record.getAttribute("right")));
          objectTypeJSON.put("uniqueId",new JSONString(record.getAttribute("uniqueId")));
          roleObject.put("objectTypeJSON",objectTypeJSON);
                              rolePermissionsArray.set(i, roleObject);
                              i++;
                          }
                      }
                  }
          I'm just iterating through it. But it gets only first value from the first changed column.

          I can also get the exact number of my smartgwt build if it is needed
          Last edited by ydmitry; 30 Jun 2014, 12:23.

          Comment


            #6
            Unless you've made an explicit call to ListGrid.saveAllEdits() any changes you make to the list grid are still stored in a pending state and won't appear with a call to getRecords. See the ListGrid APIs, especially those pertaining to an 'edit' state.

            Comment


              #7
              Also added a picture. So, each select item works correctly. I can select a value in each of them.
              Attached Files

              Comment


                #8
                Originally posted by beckyo View Post
                Unless you've made an explicit call to ListGrid.saveAllEdits() any changes you make to the list grid are still stored in a pending state and won't appear with a call to getRecords. See the ListGrid APIs, especially those pertaining to an 'edit' state.
                Thank you VERY MUCH beckyo!

                I could not understand what is going wrong for a couple of days!

                Comment

                Working...
                X