Announcement

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

    Applying client-side filter based on custom formula

    Hello, we are trying to apply a client-side filter based on a custom formula and it appears to not work. This is a time sensitive production issue for us so hoping to figure this out as soon as possible.

    Use this example in the Feature Explorer:
    http://www.smartclient.com/docs/10.0/a/system/reference/SmartClient_Explorer.html#filterBuilderBracket

    Use the code below.
    1. Right-click on Grid Header > Add Formula Column

    2. Create Formula and Save

    3. Click "Recreate Advanced Filter" button at bottom. This will add the formula field to the world datasource and add it to the Filter Builder.

    4. Enter a filter clause that should filter based on the formula you created and click Filter.

    5. It doesn't filter by the formula. If you use other fields, filtering working fine though.

    Am I doing something wrong configuring this example or is there a bug?


    Code:
    isc.FilterBuilder.create({
        ID: "advancedFilter",
        dataSource: "worldDS",
        criteria: {
            _constructor: "AdvancedCriteria",
            operator: "and",
            criteria: []
        }
    });
    
    isc.ListGrid.create({
        ID: "countryList",
        width: 550,
        height: 224,
        alternateRecordStyles: true,
        dataSource: worldDS,
        canAddFormulaFields: true,
        fields: [{
            name: "countryName"
        }, {
            name: "continent"
        }, {
            name: "population"
        }, {
            name: "area"
        }, {
            name: "gdp"
        }, {
            name: "independence"
        }]
    })
    
    isc.IButton.create({
        ID: "filterButton",
        title: "Filter",
        click: function() {
            countryList.filterData(advancedFilter.getCriteria());
        }
    })
    
    
    isc.IButton.create({
        ID: "filterButton2",
        title: "Recreate Advanced Filter",
        top: 400,
        width: 200,
        click: function() {
    
            var gridFields = countryList.getAllFields();
    
            for (var k = 0; k < gridFields.length; k++) {
                var field = gridFields[k];
    
                if (field != null && field.userFormula != null) {
                    worldDS.fields[field.name] = field;
                    console.log("adding formula field to datasource" );
                }
            }
    
    
    
            var testData = [];
    
            for (var i = 0; i <= gridFields.length; i++) {
    
                var field = gridFields[i];
    
                if (field != null) {
                    var testField = {};
                    testField.name = field.name;
                    testField.title = field.title;
                    testField.type = field.type;
                    testData[i] = testField;
                }
    
            }
    
            isc.DataSource.create({
                ID: "bigFilterDS",
                clientOnly: true,
                fields: [{
                    name: "name",
                    type: "text"
                }, {
                    name: "title",
                    type: "text"
                }, {
                    name: "type",
                    type: "text"
                }],
                testData: testData
            });
    
            isc.FilterBuilder.create({
                ID: "advancedFilter",
                fieldDataSource: "bigFilterDS",
                criteria: {
                    _constructor: "AdvancedCriteria",
                    operator: "and",
                    criteria: []
                }
            });
    
    
    
    
            filterVStack.addMember(advancedFilter, 0);
    
    
        }
    
    
    })
    
    isc.VStack.create({
        ID: "filterVStack",
        membersMargin: 10,
        members: [advancedFilter, filterButton, countryList]
    })
    
    // Perform the initial filter
    filterButton.click();

    #2
    The first problem with this code is that that's an invalid way of adding a field to a DataSource (dataSource.fields is read-only after initialization).

    But secondly, this code creates a difference between the client and server-side fields definition, such that the server doesn't know about the formula field - what are you hoping/expecting would happen if criteria are changed such that a server trip is required?

    Comment


      #3
      I'm hoping to be able to perform a client-side filter on a custom formula using the Advanced Filter. So, what would I need to change about this example to achieve that? I'm not concerned about the server trip because the filtering always happens client-side in our application.

      Comment


        #4
        I should add that we have a variety of fields that we only add client-side in our application. And, filtering works fine for them. So, there is something specifically going on with these formula fields.

        Comment


          #5
          Your sample seems to work as you expect (even with the inappropriate setting of worldDS.fields) if we add the following property to the ListGrid:

          Code:
          dataFetchMode: "local",
          This enables client-side filtering. You can find more details in the docs:
          http://www.smartclient.com/docs/10.0....dataFetchMode and
          http://www.smartclient.com/docs/10.0...ype..FetchMode.

          Note that this does mean all records will be fetched from the server at once - so that might be an issue for you.

          Comment

          Working...
          X