Announcement

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

    DataSource for ListGridField shows wrong value

    Hey guys,
    I’m currently working on a ListGrid including a ListGridField with editorType “SelectItem” which has a DataSource. Further the valueField and displayField of this ListGridField aren’t the same.

    When initially loading the ListGrid and setting it’s data everything is fine and the displayField value is visible. But when selecting another value and submitting via Enter, the value of the valueField will be visible.



    This issue is not reproduceable with a local dataSource and only appears when data has to be fetched.

    Example for reproducing the issue:
    Code:
    function clwTransformRequest(dataSourceRequest) {
        var operationType = {
            operationType : dataSourceRequest.operationType
        };
        var params = {
            sortBy : dataSourceRequest.sortBy,
            start : dataSourceRequest.startRow,
            end : dataSourceRequest.endRow
        };
        console.log(params);
        return isc.addProperties({}, operationType, dataSourceRequest.data, params);
    }
    function clwTransformResponse(dataSourceResponse, dataSourceRequest, jsonData) {
        dataSourceResponse.totalRows = jsonData.totalRows;
        dataSourceResponse.endRow = jsonData.endRow;
        dataSourceResponse.startRow = jsonData.startRow
    }
    isc.ListGrid.create({
        "ID" : "personListGrid",
        "width" : 250,
        "height" : 150,
        "canEdit" : true,
        "fields" :
        [{
                "name" : "personField",
                "title" : "Person",
                "width" : "100%",
                "canEdit" : true,
                "editorType" : "SelectItem",
                "valueField" : "number",
                "displayField" : "personDisplayField",
                optionDataSource : isc.DataSource.create({
                    "fields" :
                    [{
                            "name" : "personDisplayField",
                            "primaryKey" : true
                        }
                    ],
                    "dataFormat" : "json",
                    "dataURL" : "http://devset.de/datasource.php",
                    useHttpProxy : false,
                    "transformRequest" : clwTransformRequest,
                    "transformResponse" : clwTransformResponse,
                    "recordXPath" : "\/resultData"
                }),
                "editorProperties" : {
                    "displayField" : "personDisplayField",
                    "textMatchStyle" : "substring",
                    "loadingDisplayValue" : null
                }
            }
        ],
        "members" :
        [],
        "data" :
        [{
                "personField" : "name6",
            }
        ]
    })
    This issue is reproduceable with all current browsers and with your latest nighly build (SmartClient_v101p_2016-01-10_Pro).
    Best regards

    #2
    Look at the record your server returns when the grid performs the save - it's missing a value for the displayField, and needs one, since you've set listGridField.displayField.

    Comment


      #3
      Hey guys,
      thanks for your response. You are right, it seems I returned the wrong value for two datasource requests. I corrected that but it doesn’t seem to work out.

      I’ve made a screenshot of the FireBug output when loading my example and start editing the ListGrid (see below).

      Request 1
      Appears when loading my example, here it’s not clear what should be returned, so my none object is answered. I guess this request wants to have the selected record, but why doesn’t it ask for “personDisplayField = name6”? I tried to answer the selected record which didn’t solve my issue.

      Request 2
      Is asking for a record with “number = name6”, which doesn’t exist (record which should be returned seems to be {"personField":"name6","personDisplayField":"name6","number":6}). For debugging most probable record is answered

      Request 3
      Is asking for all records from 0 to 75 and all are returned.

      Request 4
      Is the same as Request 2 and so I’m returning the same record again.



      I can’t see which answer of these requests is missing a value, which are you referring to?
      Request 2 and 4 are asking for a record with “number = name6” which is wrong, is this caused by a wrong declaration in my example?

      Thank you for your anwser.

      Best regards

      Comment


        #4
        Yes, your setting are invalid. You have valueField:"number", but the provided record has no value for that field, hence the blank request. This is also why you later end up with "6" stored for number, since you returned that as the display value for the record.

        Once you've corrected this, be sure to read over FormItem.fetchMissingValues, which explains what these requests are and what's expected.

        Note that you don't have to do anything special to deal with these requests. If your DataSource responds correctly to fetch requests in general, no additional effort is required to handle the requests issued by the fetchMissingValues system.

        Comment


          #5
          Hey guys,

          I changed my example according to your hints. So the record provided to the list grid looks like that:
          Code:
          "data" :
          [{
                  "personField" : "name6",
                  "personDisplayField" : "name6",
                  "number" : 6
              }
          ]
          I also activated the option fetchMissingValues you mentioned to true.
          Code:
          "fetchMissingValues":true
          Doing so doesn’t effect the datasource requests I am receiving, in detail the first remains an empty request and the three following requests when starting to edit the ListGrid also remain equal to my screenshot above.
          Do you have any idea what else could be wrong?

          Thanks for your response
          Best regards

          Comment


            #6
            Just that change alone doesn't give you are a coherent set of self-consistent settings.

            Pardon us for saying so, but it really doesn't seem like you've read the docs for lgField.optionDataSource / valueField / displayField, and separately the corresponding properties for SelectItem. They are quite different - optionDataSource on a ListGridField is going to fetch the complete mapping of *all* valueField<->displayField pairs (hence your "empty" request - doing exactly what's doc'd).

            If you read the docs for listGridField.optionDataSource you'll see the possible strategies for value/displayField mapping laid out, and you probably want the latter one described (which begins with: do not set listGridField.optionDataSource).

            Comment

            Working...
            X