Server side filtering (version 5.20151.63)

Posted by: althafhussain on 14 September 2017, 11:21 am EST

    • Post Options:
    • Link

    Posted 14 September 2017, 11:21 am EST

    I want to add server side filtering and infinite scrolling to my grid. when i first load the grid, data with page size of 10, i see 10 rows in my grid. when i scroll, i retrieve the remaining rows. let say my grid has 2 columns. One column is ‘Unit Id’ and the other column is ‘Unit Code’. First row has values of ‘Unit Id’ and ‘Unit Code’ as 1 and 100.

    11th row has values of ‘Unit Id’ and ‘Unit Code’ as 2 and 100(I will see the 11th row only after i scroll as i set the default page size of 10).

    when i click the filter icon on Unit code, i see a filter options popup, with only 100 in the list(Filter by Value).

    when i click on apply i expect two rows.

    When i do the filtering by filter by condition, i should be able to use the list of options available(Equals, Does not equal, Begins with…), when i click apply, i should be able to retrive all the filtered values.Not just the rows that are visible on the grid.

    How do i achieve this?

    I read the documentation “use the filterDefinition property to perform filtering on the server.”

    view.filterDefinition = “startswith(CompanyName, ‘A’) and endswith(CompanyName, ‘B’)”;

    Also when i add infinite scrolling and filtering on flex grid, when i scroll, after retrieveing the data, scroll bar moves to the top.

    var pageSize1 = 10;

    var serviceUrl = ‘http://apitrans.**.com:80/api’;

    var entities = new wijmo.collections.CollectionView();

    var getData = function () {
        $scope.reviewList = new wijmo.odata.ODataCollectionView(serviceUrl, 'Reviews/650365', {
            fields: ['reportingDatasetID', 'unitID', 'unitCode', 'etr', 'totalTaxProvision', 'deferredTaxAsset', 'payable', 'comp_ReportingDatasetID', 'comp_ETR', 'comp_TotalTaxProvision', 'comp_DeferredTaxAsset'],
            filterOnServer: true,
            pageSize: pageSize1,
            pageOnServer: true,
            loaded: loaded
        });
    
    }
    
    $scope.init = function (s, e) {
        var flex = s;
        $scope.filter = new wijmo.grid.filter.FlexGridFilter(flex);
        s.onScrollPositionChanged = function () {
            var myDiv = $('#gsFlexGrid').find('div[wj-part="root"]');
            //$('div[wj-part="root"]');
            if (myDiv.prop('offsetHeight') + myDiv.scrollTop() >= myDiv.prop('scrollHeight')) {
                pageSize1 += 10;
    
                getData();
            }
        }
    }   
    
     getData();
    
  • Posted 14 September 2017, 11:21 am EST

    Hello Althaf,

    I believe you are loading only 10 rows initially and then, loading 10 rows each time when the user reaches the end of scrollbar from the server. If so, then filtering will be performed on the rows currently present in the CollectionView. If you apply the filter initially then it will performed on 10 rows only. If you scroll and apply then it will performed on 20 rows. Kindly refer to the following fiddle implementing your scenario: http://jsfiddle.net/1wzwdxfo/

    In this fiddle. scrollbar does not move to the top but it does moves little bit to show that more rows are available for scrolling.

    If I misunderstood anything then kindly modify the fiddle so that it replicates the issue.

    Regards

  • Posted 14 September 2017, 11:21 am EST

    Thanks for the response.

    If i have 30 total rows, and if i show only 10 rows(loading only 10 rows) initially on the grid(i will retrieve the next 20 rows after scrolling).

    Once i apply the filter(before scrolling), i would like the filter to be applied to all 30 rows, not just the 10 rows. How do i achieve this?

  • Posted 14 September 2017, 11:21 am EST

    Can you also provide me a sample for infinite scrolling with odata?

    How to pass skip and top attributes to the service?

  • Posted 14 September 2017, 11:21 am EST

    Hello Althaf,

    Unfortunately, it is not possible to apply filter on 30 rows when only 10 rows are loaded in collectionView. Since, the next 20 rows are not fetched from the server yet so collectionView does not know anything about it. Therefore, filtering cannot be applied on these rows.

    Regarding the OData sample, I am working on it and would get back to you as soon as possible.

    Regards

  • Posted 14 September 2017, 11:21 am EST

    Hi Ashish

    We have couple more question for ODATA related.

    Refer screen shot 

    1. If user click on UnitID ( filter column) we want to load filter data from server, Is there any event for which we can add event handler and send request to the server and get list of filtered unique values.
    2. After getting data from server how I can mapped to filter list?
    3. Also on click on Apply button we want to clear pagination value like skip 0 & top value to 10.

  • Posted 14 September 2017, 11:21 am EST

    Hello Althaf,

    The filter items are populated by the FlexGrid itself based on the data rows present in the CollectionView. Therefore, we cannot manually set the filter items in FlexGrid.

    Can you share the complete usecase so that I can suggest any other possible workaround accordinly ?

    Regards

  • Posted 14 September 2017, 11:21 am EST

    For the record, we have added an ODataCollectionView class to Wijmo. This class performs sorting, paging, and filtering on the server.

    You can use it like any other CollectionView, including the navigator and page navigator directives as well as the FlexGridFilter.

    You can see a quick demo here:

    http://jsfiddle.net/Wijmo5/9k7tn8e1/

    It sounds like you want to accomplish something similar to this, perhaps with a few differences. So here’s a little extra detail you may be interested in:

    1. If you want to perform filtering on the server directly from your collection view, you have to append the proper clauses to the URL when you request the data. Something like “mysvc/mytable?$filter=orderid eq 2”. Our ODataCollectionView does this automatically, and the FlexGridFilter class has a “getODataFilterDefinition” method that builds the filter for you.

    2. If you want to perform paging in the server directly from your collection view, you have to append the proper clauses as well, e.g. “mysvc/mytable?$skip=200&$top=50”. Our ODataCollectionView also does this automatically,

    3. We don’t support “infinite scrolling” because there are many definitions and use cases for this feature. You could be talking about automatic paging, or delayed loading of the data, or maybe something else. As Ashish said, if you could provide a detailed description of what you want to achieve, we should be able to help and maybe put together a sample for you.

    I hope this information is useful.

  • Posted 14 September 2017, 11:21 am EST

    1)Filtering on the Server Side:

    I want to do the filtering after the data is loaded initially.

    whgen do i invoke the below service?

    “mysvc/mytable?$filter=orderid eq 2”

    How do i dynamically change the filter conditions(lt, gt …).

    when i click the filter icon on flex grid filter header, i get a popup with two states in it.

    One state is ‘Filter By Condition’ and the other is ‘Filter by value’.

    Should i somehow prevent the default behavior of showing the pop up on filter button click and call the below service?

    “mysvc/mytable?$filter=orderid eq 2”

    But still i will be able to specify only one filter condition.

    1. “Infinite Scrolling”:

      My Use case for this feature:
    • I have a total of 30 rows.

    • By default i am showing only 10 rows. when the user scrolls the scroll bar on the grid, i want to load 10 additional rows and show 20 rows in the grid.

      $scope.filter = new wijmo.grid.filter.FlexGridFilter(flex);

      $scope.filter.onScrollPositionChanged = function () {

      var myDiv = $(‘#gsFlexGrid’).find(‘div[wj-part=“root”]’);

      if (myDiv.prop(‘offsetHeight’) + myDiv.scrollTop() >= myDiv.prop(‘scrollHeight’)) {

                $scope.Original = angular.copy($scope.reviewList.items);
                $scope.reviewList.moveToNextPage();
               
            }
        }
      
        $scope.$watch('reviewList.items', function (newVal) {
        if (newVal && $scope.Original) {
            for (var i = 0; i < $scope.Original.length; i++) {
                $scope.reviewList.items.unshift($scope.Original[i]);
            }
            
            $scope.reviewList.refresh();
        }
      

      })

      i want good implementation of the above code.

      1. Another scenario:

        I have a total of 20 rows and one column in the grid.

        Initially i load only 10 rows. Values in the 10 rows are [1, 2, 2, 4,4,4,4,4,4,4]

        Values in the next 10 rows which are still not loaded on the client side[5,5,5,5,5,5,5,5,5,5]

    when i click the filter icon, i want to make a server call and retrieve all the distinct values from 20 rows in my case[1,2,4,5](i still dint load the next 10 rows. I only have 10 rows visible on the grid. I dont want to load all 20 rows initially)

    and show it in the pop up which appears when i click the filter icon.

  • Posted 14 September 2017, 11:21 am EST

    Hi Bernardo,

    Thanks for the JSFiddle. In that demo the column filter shows the values currently in the client and only filters on those. So the be sure of your meaning, if we need to filter the entire (server-side) data, we would follow your #1 note from above?

  • Posted 14 September 2017, 11:21 am EST

    Hi Aaron

    If you are using the FlexGridFilter and ODataCollectionView classes, and filtering on the server, then you probably want to use condition filters rather than value filters. (As you pointed out, the value filter editor in this case will show only values that are currently on the client).

    To use condition filters, set the defaultFilterType property on the FlexGridFilter as follows:

    [js]// filter by condition and not by value

    // (since we don’t have all possible values on the client)

    $scope.init = function(s, e) {

    var f = new wijmo.grid.filter.FlexGridFilter(s);

    f.defaultFilterType = wijmo.grid.filter.FilterType.Condition;

    }[/js]

    I hope this helps.

  • Posted 14 September 2017, 11:21 am EST

    To clarify a little further:

    >>>>>>>>>>>>>>>>>>>>>>>

    I want to do the filtering after the data is loaded initially.

    when do i invoke the below service? “mysvc/mytable?$filter=orderid eq 2”

    How do i dynamically change the filter conditions(lt, gt …).

    >>>>>>>>>>>>>>>>>>>>>>>

    If you are using our ODataCollectionView and FlexGridFilter classes, then you don’t have to do any of this, instead you can simply let those two classes talk to each other and they will do the right thing.

    If you are using those two classes and want to initialize the filter, use the FlexGridFilter object model to do that. For example,

    [js]var cf = filter.getColumnFilter(col);

    cf.conditionFilter.condition1.operator = wijmo.grid.filter.Operator.EQ;

    cf.conditionFilter.condition1.value = 2;[/js]

    If you are using the ODataCollectionView class but not the FlexGridFilter, you can initialize the filter by setting the ODataCollectionView.filterDefinition property:

    [js]view.filterOnServer = true; // this is the default

    view.filterDefinition = ‘id eq 2’;[/js]

  • Posted 14 September 2017, 11:21 am EST

    And to add a little more background: when you filter on the server, that’s usually because you have a lot of data so you don’t want to load it all on the client.

    In this situation, even though you may only have a few possible values for a field, you probably don’t want to load all the data even on the sever just to get those values. Imagine for example you are dealing with stock data, and you have a table with price information that has several million records, but there are only maybe a thousand companies being traded, so you could get a list of possible symbols from another table.

    In order to support this type of scenario, we would have to add a new property to our ValueFilter class, one that would allow you do specify the possible values directly, as opposed to looking at the loaded data. This would probably be useful, and is something we will definitely look at in a future release.

    Thanks for bringing this up.

  • Posted 14 September 2017, 11:21 am EST

    Hi Bernardo,

    This thread relates to a problem that we are facing in our project. We are using the flexgrid in the server side mode for some screens.

    I can not use ODataCollectionView as our services do not support OData. I am already catching the sorting and pagination events to create a server request. But unfortunately the FlexGridFilter directive does not allow much flexibility in this case.

    Specifically I would like to be able to bind the unique values to the filter myself through a directive’s input argument (adding a new property to ValueFilter class as you mentioned above). Have you made any progress on this?

    Thank you

    Regards,

    Jiri

  • Posted 14 September 2017, 11:21 am EST

    Hello,

    Your query has been answered at the following forum link: http://wijmo.com/topic/flexgridfilter-unique-values-server-side-processing/#post-74223. Kindly refer to the same.

    Hope it helps.

    Thanks,

    Manpreet Kaur

  • Posted 20 November 2017, 5:57 pm EST

    http://jsfiddle.net/71f4c0a8/5/

    I wan the filer to be set on grid load and those values should be checked in the filter and other values should be unchecked

    can you see the above link?

Need extra support?

Upgrade your support plan and get personal unlimited phone support with our customer engagement team

Learn More

Forum Channels