Page 1 of 1

create a "read more" link in a field in table view

Posted: 2019-05-22 16:21
by fgazza
create a "read more" link in a field in table view

Hi everyone, does anyone have any idea how to create the typical "read more" function by a customization in the hook file or in a tablemane_tv.js file, by clicking on which you can expand a text?

Thank you!!!

Fabiano G.

Re: create a "read more" link in a field in table view

Posted: 2019-05-22 20:05
by pbottcher
Hi,

can you make a sample "screenshot" of what you try to acheive? Do you want to add additional text and buttons for the read more?

Re: create a "read more" link in a field in table view

Posted: 2019-05-22 20:36
by jsetzer
Hi,

you can try this in your TABLENAME-dv.js:

Code: Select all

// paste this in your TABLENAME-tv.js
$j(function () {

    // change tablename, columnname and length of text
    var tbl = "wirtschaftseinheit_hinweise";
    var col = "text";
    var limit = 100;

    // do not change below
    var ix = 0, i = $j("<i/>").addClass("glyphicon glyphicon-plus");

    $j("td." + tbl + "-" + col).each(function () {
        var td = $j(this), text = td.text();
        if (text.length > limit) {
            var summary = text.substr(0, limit);
            var all = $j("<span/>").attr("id", "collapse-" + (++ix)).append(text.substr(limit)).appendTo(td).css("display", "none");
            var a = $j("<button/>").attr("type", "button").addClass("more").addClass("btn btn-xs btn-default").addClass("nav-toggle").attr("href", "#collapse-" + ix).append(i.clone());
            td.html('').append(summary).append("&nbsp;").append(a).append(all);
            a.on("click", function () {
                var btn = $j(this), href = btn.attr("href"), text = $j(href).text(), e = $j(href);
                td.append(text); e.remove(); btn.remove();
            });
        }
    });
});

2019-05-22_22-34-33.gif
2019-05-22_22-34-33.gif (40.98 KiB) Viewed 2506 times
Hope this helps,
Regards,
Jan

Re: create a "read more" link in a field in table view

Posted: 2019-05-23 05:34
by fgazza
Perfect. I will try your solution soon. That's exactly what I was looking for.
One question: is there a way to make another button appear to contract the text again after expanding it?
Thank you!

Re: create a "read more" link in a field in table view

Posted: 2019-05-23 20:43
by fgazza
Ok! It work great!!!
Thank you!
Any suggestion about my second question:
is there a way to make another button appear to contract the text again after expanding it?
Thank you!