1

The column heading has class ".slick-column-name"

I added this jquery -

var text = $(".slick-column-name").text();
$(".slick-column-name").tooltip({ title: text });

But it is showing every column name in each tooltip, ( for example ID , Description, Title are column headings, so the tooltip for each column heading is being shown as "ID Description Title"

ghiscoding
  • 12,308
  • 6
  • 69
  • 112
chepeharshit
  • 43
  • 1
  • 7

2 Answers2

1

Note that I'm the author of Angular-Slickgrid and as mentioned in a comment in previous answer, Angular-Slickgrid is a wrapper on top of SlickGrid which was created few years ago (when jQuery/jQueryUI were all the hype) and so jQuery is a deep dependency.

Now to focus on your question, if we search directly in the code for the css class that you have identified, we can see this line that has the following code

$("<div class='ui-state-default slick-group-header-column' />")
            .html("<span class='slick-column-name'>" + m.name + "</span>")
            .attr("id", "" + uid + m.id)
            .attr("title", m.toolTip || "")
            .data("column", m)
            .addClass(m.headerCssClass || "")
            .addClass(hasFrozenColumns() && (columnsLength - 1) > options.frozenColumn? 'frozen': '')
            .appendTo(hasFrozenColumns() && (columnsLength - 1) > options.frozenColumn? $groupHeadersR[index]: $groupHeadersL[index]);
}

oh look at that... there's already a toolTip attribute, so where does this come from? It's a option in the column definition (column - interface in Angular-Slickgrid)

So the short answer is... just use it by making your toolTip the same as your name and you should be good to go

this.columnDefinitions = [
  { id: 'firstName', field: 'firstName', name: 'First Name', toolTip: 'First Name Tooltip' }, 
  // ...
  }
];

That should do it... note that I didn't test it but I just inspected the code to find the answer. It's always good to look directly at the code, you find a lot of answers to these questions.

EDIT

I tried it and it does work as intended with the toolTip property

enter image description here

ghiscoding
  • 12,308
  • 6
  • 69
  • 112
  • 1
    The man himself!! First of all , I want to thank you for maintaining and creating this fork, I know at least 10+ products at work that use your library! Coming to the question , I tried adding toolTip:"firstName" , but the tooltips were coming in white. I didn't know how to make them black , and i had used jquery before to use tooltips at work and those were black, so i just went with jquery. Thanks a lot again! – chepeharshit May 20 '21 at 15:40
  • Is it just a color styling issue then? You can look at the scss file and possibly contribute to fix that? ... and thanks for the nice compliments, happy to hear that and happy to get upvoted (star) if you didn't yet ;) – ghiscoding May 20 '21 at 15:54
  • I made a small mistake, the correct property to use is `tooltip` not title and it does work as can be seen in the print screen – ghiscoding May 20 '21 at 16:54
  • Yes I used the property toolTip itself. just trying to figure out how to style them. – chepeharshit May 21 '21 at 03:45
  • Those are regular browser tooltip and varies from browser to browser, the original question was answered. Styling a tooltip is a completely different subject and there's plenty of answers on the internet (it's hard to find a pure css one though) – ghiscoding May 21 '21 at 11:16
0

var text = $(".slick-column-name").text(); will return all the text for ALL columns. So you're going to get text for all elements with that class.

So if you followed it up with: console.log(text) you'd see all the column headers output to your developer console. That's as expected!

It seems you have some disconnect in what jQuery can do here - the $ selector gets ALL the elements with that class name, and is not intuitive enough to know you want a 1:1 match between the text and column header.

What you are wanting to do instead is:

  1. get all column headers (NOT TEXT)
  2. loop through each column header, and set the column name tool tip to the column header text.

I'm not 100% familiar with slickgrid, but this should give you an idea:

// I'm using $ in the variable name to label this element as a jQuery extended variable
var $columnNames = $(".slick-column-name");
$columnNames.each(function(elem) {
    // this represents a single column header
    var $elem = $(elem);
    // gets the individual text for a header
    var text = $elem.text();
    // we grab the CLOSEST parent element that matches ".slick-column-name" and set the tooltip
    var $columnHeading = $elem.closest(".slick-column-name").tooltip({ title: text });
});

I didn't verify the code, but this should send you down the path you need to hit.

Now, I assume you mean ANGULAR SLICKGRID (misspellings happen!) - you should avoid mixing jQuery in with Angular. Mixing the two can create unexpected side-effects due to re-rendering (imagine the tooltips work one minute, then you make changes, and the tooltips are gone when something changes!)

Checking out the github repository for Angular SlickGrid: https://github.com/ghiscoding/Angular-Slickgrid/blob/master/src/app/examples/grid-headerbutton.component.ts

It looks like there is a tooltip option you can use to do this through Angular as well (their example demo looks to live here: https://ghiscoding.github.io/Angular-Slickgrid/#/headerbutton )

keif
  • 580
  • 4
  • 17
  • 1
    note that I'm the author of Angular-Slickgrid, couple of things to add to this in relation to your answer. Angular-Slickgrid is a wrapper on top of SlickGrid which has a deep dependency on jQuery (maybe some day it won't but not without a full rewrite, this lib was created at the time jQuery/jQueryUI where the big hype). There's actually no need to go the jQuery way for this question, I'll post an answer – ghiscoding May 19 '21 at 14:48
  • Thanks for replying! I went with this solution at the end of the day , its probably not the best fix like ghiscoding and you mentioned. I'm new to the whole web dev scene and slickgrid is even more challenging for me, let alone JS, angular and other things. – chepeharshit May 20 '21 at 15:44