0

there is one filter functionality in my demo I will explain my problem I have one table in which i use infinite scroll is implemented In other words when user moves to bottom it load more data.There is search input field in top .Using this I am able to filter item in table .but I don't know why it is not working

When you search "ubs" and "ing" first time .it works perfectly .But when you load more data other words when user scroll to bottom and load more data the again it try to filter "ubs" and "ing" it not give any result why ?

<label class="item item-input">
    <img src="https://dl.dropboxusercontent.com/s/n2s5u9eifp3y2rz/search_icon.png?dl=0">
    <input type="text" placeholder="Search" ng-model="query">
  </label> 

secondly Actually I am implementing infinite scroll so only 100 element display .can we search element from 2000 (which I am getting from service )and display data the search result ?

Update :

9
  • I will try and update you soon .But please if you get answer please post it Commented Jun 6, 2015 at 9:32
  • I try but i got error .Please check my updated plunker plnkr.co/edit/JSV6eIVFocJvXVgiLzL8?p=preview . Commented Jun 6, 2015 at 12:06
  • could you please check where I am doing wrong ? Commented Jun 6, 2015 at 12:06
  • I think it is not correct solution ..I think we need to different way to load the data ..because when I load all data it work perfectly .but when I used infinite scroll from there is creating problem.why it is not perfect solution because some times it show data some times not .I will give you example scroll the middle the table contend search for text and press enter .sometime it display data some times not..can we use other technique to load 2000 data without hanging UI Commented Jun 6, 2015 at 14:23
  • I found issue in your plunker plnkr.co/edit/… steps to reproduce that issue is 1 ) Scroll to bottom 2 or 3 maximum 5 times mean load data more 5 times then write "group" on search text box or anything on text box then click cross(X) button you will notice that white screen display but when you touch any where in between the table it display the data why it show white screen ? did you find issue ? load data around after scroll to bottom .around 5 to six times then write "group" then press "cross" button it display white screen why ? Commented Jun 6, 2015 at 15:45

2 Answers 2

2

Here's a Plunker with everything working together. I have separated all of the pieces into individual JS files, as it was getting unruly:

Plunker

Search

The built in filter will only return results from the current view data that the ng-repeat is displaying. Because you're not loading all of the data into the view at once, you'll have to create your own search functionality.

In the demo, click the search icon to show the search box, then type your search value and press the ENTER key or click the search button to return the results.

Since you want to check whether the user pressed ENTER you have to pass both the event and the querystring to the function, so you can check for the enter keycode. The function should also run when someone clicks or taps the search button. I set ng-model="query" on the input, so query is the reference in the view. Therefore, you'll add ng-click="searchInvoices($event, query)" to your search button, and ng-keyup="searchInvoices($event, query)" to the input. And, finally, to make it easy to clear the input field, add a button that displays when the input is not empty with ng-show="query" and attach a click event with ng-click="query=null; resetGrid()".

Add the searchInvoices function to your controller. It will only run the search if either the query is empty (because you need to reset the view if the person uses the backspace key to empty the input) OR if the user pressed ENTER OR if the event was a click event in case the user clicks the search button. The inner if statement, prevents the search from running if the query is empty and just resets the view. If the query is not empty, against the total dataset and builds an array of matching results, which is used to update the view.

The last line sets the scroll position to the top of the scrollview container. This makes sure that the user sees the results without having to click somewhere in the scrollview container. Make sure you inject the $ionicScrollDelegate into your controller for this to work and set delegate-handle="invoicegrid" on your ion-scroll directive.

  $scope.searchInvoices = function(evt, queryval) {
    if (queryval.length === 0 || evt.keyCode === 13 || evt.type === 'click') {
      if (queryval.length === 0) {
        $scope.invoice_records = $scope.total_invoice_records;
      } else {
        var recordset = $scope.total_invoice_records;
        results = [];
        var recordsetLength = recordset.length;
        var searchVal = queryval.toLowerCase();
        var i, j;
        
        for (i = 0; i < recordsetLength; i++) {
          var record = recordset[i].columns;
  
          for (j = 0; j < record.length; j++) {
            var invoice = record[j].value.toLowerCase();
            if (invoice.indexOf(searchVal) >= 0) {
              results.push(recordset[i]);
            }
          }
        }
        $scope.invoice_records = results;
        $ionicScrollDelegate.$getByHandle('invoicegrid').scrollTop();
      }
    }
  };

Lastly, you need to modify the loadMore() function that is used by the infinite scroll directive, so that it doesn't try to load additional data when scrolling through the search results. To do this, you can just pass the query into loadMore on the directive like: on-infinite="loadMore(query)", then in your function, you can just run the broadcast event when the query exists. Also, removing the ngIf will ensure that the list remains dynamic.

  $scope.loadMore = function(query) {
    if (query || counter >= $scope.total_invoice_records.length) {
      $scope.$broadcast('scroll.infiniteScrollComplete');
    } else {
      $scope.counter = $scope.counter + showitems;
      $scope.$broadcast('scroll.infiniteScrollComplete');
    }
  };
Sign up to request clarification or add additional context in comments.

13 Comments

I will tell you after check your solution in 30 min
Updated the Plunker with the solution from @OrenD here: stackoverflow.com/questions/30693994/…
sorry to say your answer is incorrect I did not see that time.you acsending and descending not working properly.currentlt it is sorting current 50 elements when scroll to bottom it load more 50 element but I need it display first 50 element from 2000 object .It mean I need to sort before desplaying
when user click "V" or "^" not giving proper result or correct in this solution I am getting correct result stackoverflow.com/questions/30693994/… need to integrate in our solution
what you are doing after "^" or "V" you only sorted current 50 element which is displaing and load more data after scroll and then sorted again 50 elements .but I need to sort first 2000 object then display 50 ..than load another 50 after scroll.above link is working properly but I need to integrate with your solution
|
0

You used filter in wrong way inside ng-repeat like ng-repeat="column in invoice_records | filter:query" instead of ng-repeat="column in invoice_records | query"

  <div class="row" ng-repeat="column in invoice_records |filter:query">
    <div class="col col-center brd collapse-sm" ng-repeat="field in column.columns" ng-show="data[$index].checked && data[$index].fieldNameOrPath===field.fieldNameOrPath">{{field.value}}</div>
    <div class="col col-10 text-center brd collapse-sm"></div>
  </div>

Demo Plunkr

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.