Skip to content

Instantly share code, notes, and snippets.

@annuman97
Created April 8, 2024 10:09
Show Gist options
  • Save annuman97/c071b135b58814edd02fe76678dcbcdb to your computer and use it in GitHub Desktop.
Save annuman97/c071b135b58814edd02fe76678dcbcdb to your computer and use it in GitHub Desktop.
NTReadMoreLessButtonForMultipleColumns
/*Read More text on a table cell */
$(document).ready(function(){
var maxLength = 15; // give character length here
var colNames = ['title','citation', 'summary']; // give your column key here
var readMoreText = "read more..."; // give read more text here
var readLessText = "read less..."; //give read less text here
function limitChar(){
for(i = 0 ; i<colNames.length; i++){
$(".ninja_clmn_nm_"+colNames[i]).each(function(){
var myStr = $(this).text();
if($.trim(myStr).length > maxLength){
var newStr = myStr.substring(0, maxLength);
var removedStr = myStr.substring(maxLength, $.trim(myStr).length);
removedStr = removedStr.replace(readMoreText,'');
removedStr = removedStr.replace(readLessText,'');
$(this).empty().html(newStr);
$(this).append('<span class="more-text">' + removedStr + '</span>');
$(this).append(' <span class="read-more read-less-more" style="color:blue; cursor:pointer">'+readMoreText+'</span>');
$(this).append(' <span class="read-less read-less-more" style="color:blue; cursor:pointer">'+readLessText+'</span>');
$(this).find('.read-less').hide();
$(this).find('.more-text').hide();
}
});
$(".read-more").click(function(){
$(this).siblings(".more-text").show();
$(this).siblings(".read-less").show();
$(this).hide();
});
$(".read-less").click(function(){
$(this).siblings(".more-text").hide();
$(this).siblings(".read-more").show();
$(this).hide();
});
}
}
limitChar();
$table.on('after.ft.paging', function () {
limitChar();
});
$table.on("after.ft.filtering", function () {
limitChar();
});
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment