Image in Column Header

QuestionsImage in Column Header
edwardw asked 11 years ago

Hi
I have 25 columns with very long header names such as Nematoda_Strongyloides (N.Stron). The cell values are only 2 digits. I don't want my grid to be so very wide. Is there a way to either wrap column header text or use an image for the column header so the column header looks like this:
N
S
t
r
o
n

Thanks

13 Answers
Abu Ghufran answered 11 years ago

Yes you can use html in column title property. Use <br> for new line or <img>

$col = array();
$col["title"] = "<img width='16' src='https://www.google.com/images/srpr/logo4w.png'>&quot;; // caption of column
$col["name"] = "name";

edwardw answered 11 years ago

Hi Abu
Thanks. This should work great. Is there a way to increase the height of the column headers to allow for taller images?

Abu Ghufran answered 11 years ago

Try adding these css in html part. You can inspect using firebug and change css as desired.

<style>
/* header */
.ui-jqgrid .ui-jqgrid-htable th {height: 30px;}
.ui-jqgrid .ui-jqgrid-htable th div { height: 20px; text-align:left; padding-left: 0.3em; font-weight: bold; }
</style>

edwardw answered 11 years ago

Hi Abu
Thank you so much! Your solution worked great. The only problem with the images for column names is that those images appear in the edit screen. Is there a way to have regular text appear only in the edit screen?

Thanks again

Abu Ghufran answered 11 years ago

You can bind onload event of grid …
$e["js_on_load_complete"] = "do_onload";
$g->set_events($e);

and in JS … reset column name (image to text)

<script>
function do_onload(id)
{
jQuery("#list1").setLabel("name","Client Name"); // col-name, col-title
}
</script>

edwardw answered 11 years ago

Hi Abu
I tried your answer and it almost succeeds. With your solution it is showing the names for column header in the grid and also the edit grid. I'd like to show names only for the edit grid. I'd like to keep the images for the viewing grid.

Abu Ghufran answered 11 years ago

You can write code at these dialog (after show) event.

$opt["add_options"]["afterShowForm"] = 'function ()
{
…. // your JS code to rename label
}';

$opt["edit_options"]["afterShowForm"] = 'function ()
{
…. // your JS code to rename label
}';

$opt["view_options"]["afterShowForm"] = 'function ()
{
…. // your JS code to rename label
}';

$g->set_options($opt);

edwardw answered 11 years ago

Hi Abu
I'm trying to implement your solution but its not working. Here is my code:
$option1["edit_options"]["afterShowForm"] = '<script type="text/javascript">function ()
{
jQuery("#list1").setLabel("Nematoda_Oesophagostomum","Nematoda_Oesophagostomum");
}</script>';

Abu Ghufran answered 11 years ago

You need to remove <script type="text/javascript"> tags and closing one from string.

edwardw answered 11 years ago

Hi Abu
I followed your suggestion:
$option1["edit_options"]["afterShowForm"] = 'function ()
{
jQuery("#list1").setLabel("Nematoda_Oesophagostomum","hello world");
}';
$grid->set_options($option1);

Now the column name shows up in the grid and in the edit grid

Abu Ghufran answered 11 years ago

You need to reset the label, on edit close event.

$option1["edit_options"]["onClose"] = "…………….."

edwardw answered 11 years ago

Thank you so much for taking the time to help, Abu
This is the code:

$option1["edit_options"]["afterShowForm"] = 'function ()
{
jQuery("#list1").setLabel("Nematoda_Oesophagostomum","Nematoda Oesophagostomum");
}';
$option1["edit_options"]["onClose"] = 'function ()
{
jQuery("#list1").setLabel("Nematoda_Oesophagostomum","<img src=images/N_Oeso.png>");
}';

Now the text doesn't show in the edit window. Is there a way I can set a switch so that if the edit window is open you view the text and if the regular grid is open you see the image?

Abu Ghufran answered 11 years ago

Can you send me details where it should show image and where text.
I'll try making a demo for you.

list ?
view dialog ?
edit dialog ?
add dialog ?

Your Answer

9 + 2 =

Login with your Social Id:

OR, enter

Attach code here and paste link in question.
Attach screenshot here and paste link in question.



How useful was this discussion?

Click on a star to rate it!

Average rating 0 / 5. Vote count: 0

No votes so far! Be the first to rate it.

We are sorry that this post was not useful for you!

Let us improve this post!

Tell us how we can improve this post?