Announcement

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

    Listgrid - filter by field with dataPath

    Hi,
    I have a column with dataPath="kobi/test", and I'm trying to filter by it - with no success.
    I tested this issue with your `Local DataSource` example
    https://www.smartclient.com/smartcli...ocalDataSource
    and changed these files as follows:

    CountryDS
    *********
    isc.DataSource.create({
    ID: "countryDS",
    fields:[
    {name:"kobi", title:"Kobi"},
    {name:"countryCode", title:"Code"},
    {name:"countryName", title:"Country"},
    {name:"capital", title:"Capital"}
    ],
    clientOnly: true,
    testData: countryData
    })

    CountryData
    **********
    countryData = [
    {
    kobi: {
    test: 4
    }
    },
    {
    continent:"North America",
    countryName:"United States",
    countryCode:"US",
    area:9631420,
    population:298444215,
    gdp:12360.0,
    independence:new Date(1776,6,4),
    government:"federal republic",
    government_desc:2,
    capital:"Washington, DC",
    member_g8:true,
    article:"http://en.wikipedia.org/wiki/United_states"
    },
    ]

    dataBound.js
    ***********
    isc.ListGrid.create({
    ID: "countryList",
    width:500, height:224, alternateRecordStyles:true, showAllRecords:true,
    dataSource: countryDS,
    autoFetchData: true,
    showFilterEditor: true,
    useAdvancedCriteria:true,
    fields:[
    {name:"test", title:"Test", dataPath: "kobi/test"},
    {name:"countryCode", title:"Code"},
    {name:"countryName", title:"Country"},
    {name:"capital", title:"Capital"}
    ],
    })

    ***************

    I can't filter by this "test" column.
    When I try to filter by this column, and I run this command:
    countryList.filterEditor.getValues(),

    I get this object:
    { operator: "and",
    _constructor: "AdvancedCriteria",
    criteria: [{fieldName: "kobi/test", operator: "iContains", value: "4"}]
    }

    and the filter doesn't work.
    Can you please help?
    Last edited by kshamir; 29 Feb 2020, 22:30.

    #2
    Can anyone help me with this?

    Comment


      #3
      The problem fundamentally is that the "test" field is not actually present in the DataSource.
      To get this working you need a schema (dataSource) for the nested objects.

      Something like this:

      Code:
      isc.DataSource.create({
          ID:"nestedObject",
          fields:[
              {name:"test", type:"integer"}
          ]
      });
      
      isc.DataSource.create({
          ID: "countryDS",
          fields:[
              {name:"kobi", title:"Kobi", type:"nestedObject"},
              {name:"countryCode", title:"Code"},
              {name:"countryName", title:"Country"},
              {name:"capital", title:"Capital"}
          ],
          clientOnly: true,
          testData: countryData
      });
      Incidentally - these kinds of nested dataSources can become unwieldy.
      Where possible we typically recommend either flattening data out (so in this example "test" would become its own field in the "countryDS", with valueXPath set to extract the value from the nested data object under kobi):
      Code:
      isc.DataSource.create({
          ID: "countryDS",
          fields:[
              {name:"test", title:"Test",  valueXPath:"kobi/test"},
              {name:"countryCode", title:"Code"},
              {name:"countryName", title:"Country"},
              {name:"capital", title:"Capital"}
          ],
          clientOnly: true,
          testData: countryData
      });
      ... or using a separate dataSource with one-to-one or many-to-one relationship with the main DS defined via a foreignKey

      Regards
      Isomorphic Software

      Comment

      Working...
      X