-1

I am fetching some data from database and displaying them inside table. I need when any column value will text character will more than some certain length, it will display up to that length and other will be replace with dot (i.e-.....).

I am providing my code below.

<table class="table table-bordered table-striped table-hover" id="dataTable" >
<thead>
<tr>
<th>Sl. No</th>

<th>Specification</th>

</tr>
</thead>

<tbody id="detailsstockid">
<tr ng-repeat="pro in productDataList">
<td>{{$index+1}}</td>
<td>{{pro.specification}}</td>
</tr>   
</tbody>
</table>

In the above code for Specification contains some paragraph. I need here the paragraph should display up to 30 character, if it exceeds more than that the remaining text will replace with .....

halfer
  • 19,824
  • 17
  • 99
  • 186
satya
  • 3,508
  • 11
  • 50
  • 130
  • What do you have tried so far? After 1s googling: 1. http://sparkalow.github.io/angular-truncate/ 2. https://docs.angularjs.org/api/ng/filter/limitTo and so on – gearsdigital Jan 01 '16 at 12:56
  • Possible duplicate of [Limit the length of a string with AngularJS](http://stackoverflow.com/questions/18095727/limit-the-length-of-a-string-with-angularjs) – gearsdigital Jan 01 '16 at 12:56

2 Answers2

1

Have a look at limitTo.

You can simply do

{{ pro.specification | limitTo: 30 }} {{ pro.specification.length > 30 ? '...' : '' }}

to limit to exactly 30 characters, and if there are more than 30, it will add ellipsis to the end

UtsavShah
  • 857
  • 1
  • 9
  • 20
1

Try this: {{ pro.specification.substr(0,30) + '...' }}

Ahmet Cetin
  • 3,683
  • 3
  • 25
  • 34
  • surely @UtsavShah's solution is the Angular way doing it. I prefer to use it as my solution as it has less typing :) – Ahmet Cetin Jan 01 '16 at 13:15