1

I have a strange question ! I made a simple create/delete notes form and a script to query them all.But it will not be beautiful if someone inserts a 100KM note and the table shows it all.

I please you to suggest me a script that shows only some content of the row, and the rest when you press something like "view all". For example :

enter image description here

Brian Tompsett - 汤莱恩
  • 5,753
  • 72
  • 57
  • 129
Ion Farima
  • 309
  • 1
  • 4
  • 12

2 Answers2

1

You need to look into truncating the content string, there's a load of answers available here for both JavaScript and PHP based solutions:

JavaScript: smart way to shorten long strings with javascript
PHP: Shorten string with a "..." body

So you show the truncated string to begin with and then on the full view use the original string.

Depending on how your table in the example is setup you could also try using CSS to truncate and have it add the elipses as well.

CSS: http://css-tricks.com/snippets/css/truncate-string-with-ellipsis/

Community
  • 1
  • 1
diggersworld
  • 12,770
  • 24
  • 84
  • 119
1

Well, I think you want something like this:
Live jsfiddle

js

$(function()
{
    var maxShow = 50;
   $( ".holder" ).each(function() 
   {
       var txt = $(this).text();
       txt = txt.substr(0,maxShow)+' ...';
       $(this).prev().prev().text(txt);
   });
  $(".show").click(function()
  {
      var txt = $(this).next('span').text();
      $(this).parent().text(txt);
  });
});

html

<div class='txt'><span class='summery'></span><a href="#" class="show">view</a><span class='holder'> 0 I have a strange question ! I made a simple create/delete notes form and a script to query them all.But it will not be beautiful if someone inserts a 100KM note and the table shows it</span></div>
<div class='txt'><span class='summery'></span><a href="#" class="show">view</a><span class='holder'> 1 I have a strange question ! I made a simple create/delete notes form and a script to query them all.But it will not be beautiful if someone inserts a 100KM note and the table shows it</span></div>
<div class='txt'><span class='summery'></span><a href="#" class="show">view</a><span class='holder'> 2 I have a strange question ! I made a simple create/delete notes form and a script to query them all.But it will not be beautiful if someone inserts a 100KM note and the table shows it</span></div>

css

.holder
{
  display:none;
}
Siamak Motlagh
  • 5,028
  • 7
  • 41
  • 65