jqGrid 3.5 with jQuery UI ThemeRoller Themes Demos
jqGrid 3.5 was released yesterday. It includes lots of good features, including a new rendering engine for faster loading. It also now supports jQuery UI ThemeRoller themes, so to start off itself you have access to variety of styles and can create your own easily too.
So I went ahead and created a demo that shows the grid in all these themes.
View Demo
How I did this style selection switch, follows
The creation of grid hasn't changed and all that script remains the same, I have blogged about it before. The main thing to look at here is using ColdFusion with jQuery to implement the style switching. There are probably others (and maybe better) ways to do this, but here I describe how I came about doing it.
The first thing to do was to make it scaleable, that means I don't have to know the names of the themes and don't have to change any code if a theme based on ThemeRoller is added in the future. We use good old cfdirectory for that and read all the ThemeRoller theme subdirectories from the css directory within our path. Then I build the form using cfselect and cfinput.
2 <cfdirectory action="list" directory="#GetDirectoryFromPath(GetTemplatePath())#css" type="dir" name="dirContents">
3 <!--- Either the selected theme is passed in otherwise we set it to the first theme in directory --->
4 <cfparam name="Form.cssName" default="#dirContents.name#">
5 <!--- Our Form that displays the selections --->
6 <cfform action="gridtest1.cfm" id="cssForm" name="cssForm">
7 <table>
8 <tr><td>Themes:</td><td>
9 <cfselect query="dirContents" display="name" value="name" name="cssList" id="cssList" selected="#Form.cssName#">
10 </cfselect></td></tr>
11 <tr><td>
12 Current Theme:</td><td>
13 <cfinput type="text" id="cssName" name="cssName" value="#Form.cssName#">
14 </td></tr>
15 </table>
16 </cfform>
2 {
3 // We are preventing loading a file already loaded
4 var _links = document.getElementsByTagName("link");
5 var _head = document.getElementsByTagName("head")[0];
6
7 // Loop through the length of the links
8 for( i = 0; _links.length > i; i++)
9 {
10 // If the href is already present, remove it
11 if (_links[i]["href"] == url_)
12 {
13 _head.removeChild(_links[i]);
14 }
15 }
16
17 // Optional parameters check
18 var _media = media_ === undefined || media_ === null ? "all" : media_;
19
20 // Build link element
21 var _elstyle = document.createElement("link");
22 _elstyle.setAttribute("rel", "stylesheet");
23 _elstyle.setAttribute("type", "text/css");
24 _elstyle.setAttribute("media", _media);
25 _elstyle.setAttribute("href", url_);
26
27 // Add style
28 _head.appendChild(_elstyle);
29 }
2 sel = document.cssForm.cssName.value;
3 $("#cssList").change(function()
4 {
5 var selStyle = $("#cssForm option:selected").val();
6 document.cssForm.cssName.value = selStyle;
7 document.cssForm.submit();
8 });
9 var loadVar = "css/" + sel + "/jquery-ui-1.7.2.custom.css";
10 load(loadVar);
11 </script>
Your writing is good and you write about what I want read.
Thanks
Your article just awesome...
I cannot use cfgrid for some reason and I am trying your demo, but I have javscript error, I cannot dowload jqGrid 3.5 this link blocked.
Without these plugins it doesn't work.
Please help.
Thanks
The jqGrid link should be working again, looks like they had some hosting problems.
As for cfgrid, when you use it make sure to turn of Request Debugging in ColdFusion Administrator.
Thanks for quick response,
I have developed very siplme code for our purpose,
I've get data from cfdirectory and put result into cfgrid,
It works on my PC fine, but it doesn't on production unix box.
I have RSL failed to load error, that why
I am trying to use your latest jqGrid
That sounds like an error with the with the ColdFusion setup. Google tells me it has something to do with not granting access to CFIDE/scripts/ directory.