Search in Columns

20 views
Skip to first unread message

Shiva Rowshan rad

unread,
Jun 25, 2016, 3:08:30 PM6/25/16
to AngularJS
Hi everyone
I have a Json Data which I showed in rows with 2 columns. I put a search box to show the search results by filter . but it does not work correctly .
Sometimes it shows both data and its next index , sometimes it shows the data in both columns of a row and sometimes it shows nothing at all.
 How should I make it correct ?


<input type="text" ng-model="search" />
<div class="row" ng-repeat="x in books | filter:search" ng-if="$index%2==0">
<div class="col" > {{x.name}}  , {{x.type}} </div>
<div class="col" > {{books [$index+1].name}}  , {{books [$index+1].type}} </div>
</div>

Zlatko Đurić

unread,
Jun 26, 2016, 3:02:45 AM6/26/16
to AngularJS


On Saturday, June 25, 2016 at 9:08:30 PM UTC+2, Shiva Rowshan rad wrote:
Hi everyone
I have a Json Data which I showed in rows with 2 columns. I put a search box to show the search results by filter . but it does not work correctly .
Sometimes it shows both data and its next index , sometimes it shows the data in both columns of a row and sometimes it shows nothing at all.
 How should I make it correct ?



So two things to note here:

1. I don't know what your problem exactly is - perhaps you're matching stuff from "book.type", "book.author" or whatever else property, not just name.

If you want to limit the search, just limit it to your name property directly:
      
    <input ng-model="search.name"></label><br>
    <tr ng-repeat="item in items | filter:search">
        {{ item.name }} - {{ item.type }}
    </tr>



2. Layout - you have a weird thing there with ng-if:

     ng-if="$index%2==0"

That would limit you to only show every second row of the array (filtered or full, regardless). Why is that? Are you trying to lay the data out in two columns?
Why not simply use some simple grid?

Like: 

    <div class="results grid">
      <div class="col-1-2" ng-repeat="item in items">
        <span>{{ item.name }}, {{ item.type }}</span>
      </div>
    </div>


Shiva Rowshan rad

unread,
Jun 26, 2016, 4:26:28 AM6/26/16
to AngularJS
Thanks , I used col-1-2 class but it only shows one column in grid :( I cant understand why this happens.

Shiva Rowshan rad

unread,
Jun 26, 2016, 4:28:38 AM6/26/16
to AngularJS
By the way I'm using angularjs in Ionic Framework for building a mobile app using Phonegap. 

Zlatko Đurić

unread,
Jun 26, 2016, 7:15:27 AM6/26/16
to ang...@googlegroups.com
col-1-2 is just from my plunker, my sample. Pretty sure Ionic has some sort of a grid too, you'll have to read the docs about it.
--
You received this message because you are subscribed to a topic in the Google Groups "AngularJS" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/angular/7JhHnjSm6SA/unsubscribe.
To unsubscribe from this group and all its topics, send an email to angular+u...@googlegroups.com.
To post to this group, send email to ang...@googlegroups.com.
Visit this group at https://groups.google.com/group/angular.
For more options, visit https://groups.google.com/d/optout.

Shiva Rowshan rad

unread,
Jun 27, 2016, 4:57:39 PM6/27/16
to AngularJS
yes Ionic has row and col classes for grid and i used in my code.

Zlatko Đurić

unread,
Jun 27, 2016, 5:25:37 PM6/27/16
to ang...@googlegroups.com
Well then maybe stackoverflow or some ionic forum might be good next steps, if you can't find the issue.


On Monday, 27 June 2016, Shiva Rowshan rad <shiva...@gmail.com> wrote:
yes Ionic has row and col classes for grid and i used in my code.

--
You received this message because you are subscribed to a topic in the Google Groups "AngularJS" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/angular/7JhHnjSm6SA/unsubscribe.
To unsubscribe from this group and all its topics, send an email to angular+u...@googlegroups.com.
To post to this group, send email to ang...@googlegroups.com.
Visit this group at https://groups.google.com/group/angular.
For more options, visit https://groups.google.com/d/optout.


--
Zlatko
Reply all
Reply to author
Forward
0 new messages