This is a migrated thread and some comments may be shown as answers.

"read more" functionality for grid cells.

1 Answer 896 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Maitri
Top achievements
Rank 1
Veteran
Maitri asked on 08 Apr 2020, 03:56 PM

How to have 'read more' and 'read less' functionality if there is large content in a cell in Kendo grid for Angular 6 ?

So inside cell on the third line of text we could have a 'read more'  and on clicking on 'read more' the row expands vertically and shows the rest of the content ending with 'read less'. 

1 Answer, 1 is accepted

Sort by
0
Dimiter Topalov
Telerik team
answered on 10 Apr 2020, 05:52 AM

Hello Maitri,

The developer can utilize the Grid Cell template to provide any desired custom logic and content to the respective cells:

https://www.telerik.com/kendo-angular-ui/components/grid/columns/templates/#toc-cell-template

A "read more"/"less" button could be displayed conditionally based on the length of the cell content - for example the first X characters from the text can be displayed in a custom div/span element with ellipsis and a "read more" button in the end.

Another element, holding the rest of the text (or a new element, holding the whole text) can be shown when the button is clicked (for example, via *ngIf and toggling some boolean field). Again, when the whole content is displayed, another button at the end of the whole content can toggle the same boolean back, thus hiding the long text container, and displaying again the short text container.

I hope this helps.

Regards,
Dimiter Topalov
Progress Telerik

Progress is here for your business, like always. Read more about the measures we are taking to ensure business continuity and help fight the COVID-19 pandemic.
Our thoughts here at Progress are with those affected by the outbreak.
Tushar
Top achievements
Rank 1
commented on 27 Jan 2022, 10:47 AM

Hi Dimiter,
i have tried the same way as you have explained, but the issue is when we do it for one row it gets applied to all the rows which has the length of the cell content more than X characters.

how can we target the single row on which we are doing the operation read more/less.
Maitri
Top achievements
Rank 1
Veteran
commented on 27 Jan 2022, 11:01 AM | edited

Hi Tushar,

One workaround to target the single row on which user has clicked is by adding a boolean property like IsReadMore in your object and then on read more button click pass the dataItem to the function and inside the function set the IsReadMore flag TRUE for that particular dataItem. And based on this flag you can show/hide your content.

Ex:

<a (click)="onClick(dataItem)"> read more... </a>

onClick(dataItem)

{

dataItem.IsReadMore = true;

}

Tushar
Top achievements
Rank 1
commented on 27 Jan 2022, 02:49 PM | edited

Hi Maitri,

thanks alot, it worked.
Tags
Grid
Asked by
Maitri
Top achievements
Rank 1
Veteran
Answers by
Dimiter Topalov
Telerik team
Share this question
or