Author Topic: Icon in column header  (Read 2253 times)

queensgambit9

  • Pro Ultimate
  • Sr. Member
  • *
  • Posts: 349
    • View Profile
Icon in column header
« on: June 18, 2025, 04:52:42 pm »
Hi

I would like add a icon to column header for a specific column after the title. But not being a part of the title.
What would be the best approach for this?

paramvir

  • Administrator
  • Hero Member
  • *****
  • Posts: 6406
    • View Profile
Re: Icon in column header
« Reply #1 on: June 18, 2025, 06:40:35 pm »
If you don't want it to be part of title API, then

In refreshHeader event, get a reference to header cell with getCellHeader method

https://paramquery.com/pro/api#method-getCellHeader

and add icon by DOM manipulation.

queensgambit9

  • Pro Ultimate
  • Sr. Member
  • *
  • Posts: 349
    • View Profile
Re: Icon in column header
« Reply #2 on: June 19, 2025, 07:02:10 pm »
Thanks, I got this:

Code: [Select]
refreshHeader: function(event, ui) {
                var $cell = this.getCellHeader( { colIndx: 0 } );
                $cell[0].append("<div></div>");   
            }

But the div is not inserted correctly...
« Last Edit: June 19, 2025, 07:04:14 pm by queensgambit9 »

paramvir

  • Administrator
  • Hero Member
  • *****
  • Posts: 6406
    • View Profile
Re: Icon in column header
« Reply #3 on: June 19, 2025, 07:15:04 pm »
Another method:

Add class to the header cell:

Code: [Select]
{ title: "ShipCountry", width: 100, dataIndx: "ShipCountry", clsHead: 'icon-class' },

Use css ::before or ::after pseduo-element

Code: [Select]
<style>
.icon-class .pq-title-span::after{
  display: inline-block;
  font-family: bootstrap-icons !important; 
  font-style: normal;
  font-weight: normal !important;
  font-variant: normal;
  text-transform: none;
  line-height: 1;
  vertical-align: -.125em;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
  font-size:14px; 
  content: "\f214"; /* Unicode for calendar icon in Bootstrap Icons, replace with ucincode of your choice */
margin-left: 10px;
}
</style>

or use emoji

Code: [Select]
.icon-class .pq-title-span::after{
  content: "✂️";
  margin-right: 5px;
}
« Last Edit: June 19, 2025, 07:32:32 pm by paramvir »

paramvir

  • Administrator
  • Hero Member
  • *****
  • Posts: 6406
    • View Profile
Re: Icon in column header
« Reply #4 on: June 19, 2025, 07:31:32 pm »
Code example of adding icon using DOM manipulation:

Code: [Select]
refreshHeader: function(evt, ui) {
var $headerCell = this.getCellHeader({ colIndx: 0 });
var $title = $headerCell.find('.pq-title-span');
// Prevent duplicate icons
if ($headerCell.find('.ui-icon-disk').length === 0) {
$("<span class='ui-icon ui-icon-disk'></span>").insertAfter($title);
}
},
« Last Edit: June 19, 2025, 07:38:31 pm by paramvir »