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

Discussions related to customizing hooks. Hooks are documented at http://bigprof.com/appgini/help/advanced-topics/hooks/
Post Reply
fgazza
Veteran Member
Posts: 205
Joined: 2019-04-30 17:37

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

Post by fgazza » 2019-05-22 16:21

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.

pbottcher
AppGini Super Hero
AppGini Super Hero
Posts: 1635
Joined: 2018-04-01 10:12

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

Post by pbottcher » 2019-05-22 20:05

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?
Any help offered comes with the best of intentions. Use it at your own risk. In any case, please make a backup of your existing environment before applying any changes.

User avatar
jsetzer
AppGini Super Hero
AppGini Super Hero
Posts: 1807
Joined: 2018-07-06 06:03
Location: Kiel, Germany
Contact:

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

Post by jsetzer » 2019-05-22 20:36

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 1779 times
Hope this helps,
Regards,
Jan
Kind regards,
<js />

My AppGini Blog:
https://appgini.bizzworxx.de/blog

You can help us helping you:
Please always put code fragments inside [code]...[/code] blocks for better readability

AppGini 24.10 Revision 1579 + all AppGini Helper tools

fgazza
Veteran Member
Posts: 205
Joined: 2019-04-30 17:37

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

Post by fgazza » 2019-05-23 05:34

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!

fgazza
Veteran Member
Posts: 205
Joined: 2019-04-30 17:37

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

Post by fgazza » 2019-05-23 20:43

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!

Post Reply