Announcement

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

    How to pass fields to server in ListGrid?

    I started this thread based on https://forums.smartclient.com/forum...rails-back-end to isolate the question I posted there: How can I send the field names of the ListGrid to the server via the RestDataSource (RubyOnRails server)?

    I've tried setting dataProperties.requestProperties.outputs in the grid's init() method and use transformRequest() in a subclass of RestDataSource to send those outputs to the server and this works, until I filter data (via the filterEditor).

    I have something working now by overriding fetchData() and filterData() in the subclass of ListGrid I've created:

    Code:
    fetchData: function (criteria, callback, request) {
      request.fields = this.getAllFields().getProperty('name');
      return this.Super('fetchData', [criteria, callback, request]);
    },
    
    filterData: function (criteria, callback, request) {
      request.fields = this.getAllFields().getProperty('name');
      return this.Super('filterData', [criteria, callback, request]);
    },
    ...
    Is this a correct approach?

    #2
    As covered in your other thread, this both shouldn't be necessary and wouldn't work anyway.

    It's also unnecessary in another way: the dsRequest contains the componentId, so if you wanted the field names you could just interrogate the component in DataSource.transformRequest().

    Comment


      #3
      Well actually, this works! Extending the example I just posted in that other thread, it becomes:

      Code:
      isc.ListGrid.create({
        allowFilterOperators: true,
        alwaysShowOperatorIcon: true,
        autoDraw: true,
        dataSource: isc.RestDataSource.create({
          dataFormat: 'json',
          dataURL: '/users.json',
          fields: [
            { hidden: true, name: 'id', primaryKey: true, type: 'integer' },
            { name: 'full_name', type: 'text' },
            { name: 'locale_code', optionDataSource: 'LOCALE_ENUM', type: 'text' }
          ],
          jsonPrefix: '',
          jsonSuffix: '',
          operationBindings: [{ dataProtocol: 'postMessage', operationType: 'fetch' }],
          transformRequest: function (request) {
            request.data ||= {};
            request.data.outputs = request.outputs;
            return this.Super('transformRequest', [request]);
          }
        }),
        fields: [
          { name: 'full_name', title: 'Full name' },
          { name: 'locale_code', displayField: 'name', title: 'Locale', valueField: 'code', width: 100 }
        ],
        filterData: function (criteria, callback, request) {
          console.log('filterData', arguments);
          request.outputs = this.getAllFields().getProperty('name');
          this.Super('filterData', [criteria, callback, request]);
        },
        height: '100%',
        showFilterEditor: true,
        width: '100%'
      });
      Just added the filterData() method (fetchData() isn't needed) and removed init(), and it works! Passes the outputs to the server! And logs the call to filterData().

      The idea with the componentID is interesting! But I think I would only want to send outputs in case of a Grid, but I might check if that component subclasses ListGrid.
      Last edited by wallytax; 22 Feb 2022, 12:24.

      Comment

      Working...
      X