Tuesday, April 10, 2012 #

Blog has moved–feed changed

To all reading this via my rss feed, please update the feed url to http://feeds.feedburner.com/stevecl

After the google owns feedburner change I cannot access my original feed – it says its migrated, but not to my account!!

Nothing more will be coming through on this feed.

Posted On Tuesday, April 10, 2012 10:44 PM | Comments (0)

Friday, March 9, 2012 #

PowerShell script to find where in a site collection a specific feature is enabled.

It’s not an uncommon task to want to find out in what webs you have a specific feature enabled.  This little script does just that, taking 2 params (site collection url, feature name) and simple output the SharePoint web url.  Nothing fancy, but certainly a useful script to have in your toolbox!

A good example of this is where you are using content publishing going from an Enterprise internal farm to a Foundation external farm, certain feature won’t be in the Foundation farm and will cause the Content Publisher to fail, it will be so kind as to tell you what feature is causing the problem, but not where it is!  Someone somewhere has enabled a feature they shouldn’t have!!!

I’m sure some “one line wizards” could optimise this script – but that’s not my bag – I’m interested in getting the job done for our clients and providing a useful script we can use again and again.

You could of course add in Disable-SPFeature command if you wanted to do that at the same time…

Feature Finder script
  1. #Powershell script to identify where in a site collection a specific feature is enabled
  2. #Version: 1.0
  3. #Author: Steve Clements | Perspicuity Ltd
  4. #Params:
  5. #$siteCollectionUrl - url of the site collection
  6. #$featureName - name of the feature you want to find
  7.  
  8.  
  9. param ([string] $siteCollectionUrl, [string] $featureName)
  10.  
  11. if(!$siteCollectionUrl -or !$featureName) {
  12.     Write-Host -ForegroundColor Red "You must provide a site collection url and feature name to find!"
  13.     break
  14. }
  15.  
  16. Write-Host -BackgroundColor DarkGreen "Feature '"$featureName "' exists in these sites"
  17.  
  18. Get-SPSite $siteCollectionUrl | ForEach-Object {
  19.     Get-SPWeb -Site $_ | ForEach-Object {
  20.       $f = Get-SPFeature -Web $_ | Where {$_.DisplayName -eq $featureName}
  21.       if($f) {
  22.           Write-Host $_.Url
  23.       }
  24.     }
  25. }
  26.  
  27. Write-Host -BackgroundColor DarkGreen "Done"

Posted On Friday, March 9, 2012 3:21 PM | Comments (1)

Gotcha: 403 and 401 errors in SharePoint using Anonymous access

Recently I came up against a problem where I was getting 401 Unauthorized and 403 Forbidden errors in SharePoint on an extended anonymous only site.

It worked perfectly when using windows authentication, for any level of user.

In the end I tracked the problem down to accessing SPContext.Current

I found this article which states you should use SPSecurity.RunWithElevatedPrivileges when using the current context and it worked!!

A little surprising, but not unexpected the SharePoint logs showed nothing about this problem.

Check out the link above which gives a perfect little code snippet of how to resolve the problem.

Posted On Friday, March 9, 2012 2:24 PM | Comments (0)

Tuesday, March 6, 2012 #

Enable Publishing Approval workflow on all SP Web(s) in an Site collection with Powershell

What you need / What you've got?

  1. Pretty obvious, when a user edits/changes a page, you need someone to check its all good before it goes live! Aka Publishing Approval
  2. You can use the "Publishing site with workflow" template or enable it manually or set it up in your custom site definition.
  3. BUT...you've got an entire site collection full of web sites and you need to do it "en-mass" … step up Powershell.
    1. A common scenario could be you were working in Stage or Pre-go live and having Approval workflow just isn't practical or required. Now its live...you need and want it.

What you need to do to SharePoint...

  1. Enable Moderation on the library (that is Content Approval in UI)
  2. Enable Minor Versions (that’s is 1.1, 1.2 etc)
  3. Create the Workflow History list and enable the Workflow History feature (hiding this list is optional, but I think its best, showing the list offers nothing to the user, you can access the same history looking at the workflow status screen, which is far more usefully presented)
  4. Create the Workflow Tasks list
  5. Associate the "Publishing Approval" workflow to the library
  6. Set the properties on the WorkFlow association
    1. This is your choice, but I have set AllowManual to true, AutoStartCreate and Change to false
  7. Add the association
  8. You would be forgiven in thinking that’s it, job done...but you will find that the even though the workflow is there, it doesn't the "major check-in" property enabled so the experience for the user is different i.e they have to choose the non-default option to fire the workflow.
  9. You need to set the property DefaultContentApprovalWorkflowId to the id of the Workflow association object, what tricked me up...even though in the UI the property is in the workflow with the other workflow properties, but this property is on the library.
  10. Still not done...now, the workflow is firing great, but every status is "Rejected". Why? Because you need to Update the workflow association data.
  11. For this I cheated and setup 1 workflow on the pages library, with the correct actions and Approvers group, then went into SharePoint Manager and grabbed the xml from there.
  12. Also I set the Enabled property to true and call WorkflowAssociations.Update(myAssociation) to set both new properties…
  13. Yes, that’s it...you are actually done now!!!

The Magic

This script is 99% influenced by this post http://bit.ly/AcOa2s, I’ve butchered it and added the extra stuff required… FYI: http://get-spscripts.com is a great resource for SharePoint PowerShell scripts...the scripts published are always of high quality, well commented and explained - bookmark it if you don't like thrashing.

The crazy colours and rather OTT output is my fault!

I’ve also put the params at the top – not overly user friendly, but this is perfect for my requirements…you can easily change that!

 

PowerShell script
  1.  
  2. $url = "<site collection URL>"
  3. $list = "Pages"
  4. $workFlowName = "Publishing Approval"
  5. $wfassname = "Page Approval"
  6.  
  7.  
  8.  
  9. function AddWorkflowToLibraries ($SiteCollection, $ListName, $WfName, $WfAssociationName)
  10. {
  11.    #Get site object and create blank guid to store workflow template ID
  12.     $site = Get-SPSite $SiteCollection
  13.    [Guid]$wfTemplateId = New-Object Guid
  14.     
  15.     # Get every sub web
  16.     Get-SPWeb -Site $site | ForEach-Object {
  17.           Write-Host -ForegroundColor White -BackgroundColor DarkMagenta "WEB: "$_.Title$_.Url
  18.         
  19.         #Do the following if a list exists with the name specified by the user - e.g., Pages
  20.         if ($_.Lists[$ListName]) {
  21.             Write-Host "PROCESS:"$listName "list"
  22.             
  23.             #
  24.             # Get list and set version properties
  25.             #
  26.             $list = $_.Lists[$ListName]
  27.             $list.EnableModeration = $true
  28.             $list.EnableMinorVersions = $true
  29.             $list.Update()
  30.             
  31.            #Go through each workflow installed in the site to find the correct ID            
  32.             foreach ($wfTemplate in $_.WorkflowTemplates) {
  33.                 if ($wfTemplate.Name -eq $WfName) {
  34.                    $wfTemplateId = $wfTemplate.Id
  35.                }
  36.            }
  37.             
  38.             #
  39.             #SETUP WORKFLOW HISTORY LIST
  40.             #
  41.             $wfTemplate = $_.WorkflowTemplates[$wfTemplateId]
  42.             if($wfTemplate -eq $null) {
  43.                 Write-Host "ERROR: Workflow '"$WfName "' with ID '"$wfTemplateId "' NOT found" -BackgroundColor Red -ForegroundColor White
  44.             }
  45.             else {
  46.                 #Check if the site already has a workflow history list - if not, create it
  47.                 if(!$_.Lists["Workflow History"])
  48.                 {
  49.                     Write-Host "CREATE: Workflow History list" -ForegroundColor Blue
  50.                     
  51.                     $_.Lists.Add("Workflow History", "A system library used to store workflow history information that is created in this site.  It is created by the Publishing feature.",
  52.                     "WorkflowHistory", "00BFEA71-4EA5-48D4-A4AD-305CF7030140", 140, "100")
  53.                     
  54.                     if (!$_.Features["00BFEA71-4EA5-48D4-A4AD-305CF7030140"]) {
  55.                         Enable-SPFeature -Identity WorkflowHistoryList -Url $_.Url
  56.                     }
  57.                     $wfHistory = $_.Lists["Workflow History"]
  58.                     $wfHistory.Hidden = $true
  59.                     $wfHistory.Update()
  60.                 }
  61.                 else
  62.                 {
  63.                     Write-Host "FOUND: Workflow History list" -ForegroundColor green
  64.                     $wfHistory = $_.Lists["Workflow History"]
  65.                 }
  66.                 
  67.                 #
  68.                 #Check if the site already has a workflow tasks list - if not, create it
  69.                 #
  70.                 if(!$_.Lists["Workflow Tasks"]) {
  71.                     $_.Lists.Add("Workflow Tasks", "This system library was created by the Publishing feature to store workflow tasks that are created in this site.", "WorkflowTasks", "BF611337-1591-49f4-BF42-CE7BE53852D8", 107, "100")
  72.                     Write-Host "CREATE: Workflow Tasks list" -ForegroundColor Blue
  73.                 }
  74.                 else {
  75.                     Write-Host "FOUND: Workflow Tasks list" -ForegroundColor green
  76.                 }
  77.                 $wfTasks = $_.Lists["Workflow Tasks"]
  78.                 
  79.                 #
  80.                 #new up workflow association (extra associated data can be added if you have it)
  81.                 #
  82.                 $wfAssociation = [Microsoft.SharePoint.Workflow.SPWorkflowAssociation]::CreateListAssociation($wfTemplate, $WfAssociationName, $wfTasks, $wfhistory)
  83.                 $wfAssociation.AllowManual = $true
  84.                 #$wfAssociation.AllowAsyncManualStart = $true
  85.                 $wfAssociation.AutoStartChange = $false
  86.                 $wfAssociation.AutoStartCreate = $false
  87.                 
  88.                 #
  89.                 #Check to see if the association has already been added to the list
  90.                 #
  91.                 [guid]$wfId = New-Object Guid
  92.                 [bool]$wfFound = $false
  93.                 
  94.                 foreach ($wf in $list.WorkflowAssociations) {
  95.                     if ($wf.Name -eq $wfAssociation.Name) {
  96.                         $wfId = $wf.Id
  97.                         write-host "FOUND: Workflow"$wf.Name"already exists on"$list.Title"list in site"$_.Title -ForegroundColor green
  98.                         $wfFound = $true
  99.                     }
  100.                 }
  101.                 #If association is already there, ignore the add (and optionally delete it)
  102.                 if ($wfFound -eq $true) {
  103.                     #Command to remove existing workflow from list before adding new one, if required
  104.                     #$list.WorkflowAssociations.Remove($wfId)
  105.                     write-host "REMOVE: Workflow"$wfAssociation.Name"from"$list.Title"in site"$_.Title -ForegroundColor Magenta
  106.                 }
  107.                 #else, add it to the workflow association to the list
  108.                 else
  109.                 {
  110.                     #Create the association
  111.                     $list.WorkflowAssociations.Add($wfAssociation) | Out-Null
  112.                     
  113.                     #Set the association data (for approvers and approval steps
  114.                     $wfAssociation.AssociationData = Get-AssociationData
  115.                     #enable is not available until its associated.
  116.                     $wfAssociation.Enabled = $true
  117.                     
  118.                     $list.WorkflowAssociations.Update($wfAssociation)
  119.                     
  120.                     $list.DefaultContentApprovalWorkflowId = $wfAssociation.Id
  121.                     $list.Update()
  122.                     write-host "CREATE: Workflow"$wfAssociation.Name"to"$list.Title"in site"$_.Title -BackgroundColor Cyan -ForegroundColor Red
  123.                 }
  124.             }
  125.         }
  126.         else {
  127.             Write-Host -BackgroundColor DarkRed -ForegroundColor White "No"$listName" list found"
  128.         }
  129.     }
  130.     
  131.    #Dispose of Site object
  132.     $site.Dispose()
  133. }
  134. function Get-AssociationData() {
  135.     return "<dfs:myFields xmlns:xsd=`"http://www.w3.org/2001/XMLSchema`" xmlns:dms=`"http://schemas.microsoft.com/office/2009/documentManagement/types`" xmlns:dfs=`"http://schemas.microsoft.com/office/infopath/2003/dataFormSolution`" xmlns:q=`"http://schemas.microsoft.com/office/infopath/2009/WSSList/queryFields`" xmlns:d=`"http://schemas.microsoft.com/office/infopath/2009/WSSList/dataFields`" xmlns:ma=`"http://schemas.microsoft.com/office/2009/metadata/properties/metaAttributes`" xmlns:pc=`"http://schemas.microsoft.com/office/infopath/2007/PartnerControls`" xmlns:xsi=`"http://www.w3.org/2001/XMLSchema-instance`"><dfs:queryFields /><dfs:dataFields><d:SharePointListItem_RW><d:Approvers><d:Assignment><d:Assignee><pc:Person><pc:DisplayName>Approvers</pc:DisplayName><pc:AccountId>Approvers</pc:AccountId><pc:AccountType>SharePointGroup</pc:AccountType></pc:Person></d:Assignee><d:Stage xsi:nil=`"true`" /><d:AssignmentType>Serial</d:AssignmentType></d:Assignment></d:Approvers><d:ExpandGroups>false</d:ExpandGroups><d:NotificationMessage /><d:DueDateforAllTasks xsi:nil=`"true`" /><d:DurationforSerialTasks xsi:nil=`"true`" /><d:DurationUnits>Day</d:DurationUnits><d:CC /><d:CancelonRejection>true</d:CancelonRejection><d:CancelonChange>true</d:CancelonChange><d:EnableContentApproval>true</d:EnableContentApproval></d:SharePointListItem_RW></dfs:dataFields></dfs:myFields>"
  136. }
  137.  
  138. AddWorkflowToLibraries $url $list $workFlowName $wfassname

Posted On Tuesday, March 6, 2012 6:19 PM | Comments (0)

SharePoint 2010 set ‘Start this workflow to approve publishing a major version of an item’ with Powershell

Took me a little while to figure this one out, you’ve assigned your workflow to a library and you can set all other other flags like “AllowStartChange” and “AllowStartCreate”, but cant see how to set “Start this workflow to approve publishing a major version of an item.”

That’s because its a property on the library itself called “DefaultContentApprovalWorkflowId”

 

So you might want to do something like this…where you have the WorkFlow Association object ($wfAssociation) and the list/library ($list).

$wfAssociation = [Microsoft.SharePoint.Workflow.SPWorkflowAssociation]
::CreateListAssociation(……
$list.WorkflowAssociations.Add($wfAssociation) | Out-Null
$list.DefaultContentApprovalWorkflowId = $wfAssociation.Id
$list.Update()

Resources:

This is probably the best Associate workflow to list/library with Powershell example out there http://bit.ly/AcOa2s

Posted On Tuesday, March 6, 2012 11:52 AM | Comments (0)

Saturday, December 3, 2011 #

Minify JS and CSS in Visual Studio Build Events

It’s pretty widely accepted (and common sense) that if you’re putting a site out into the wild – such a simple task as minifying CSS and JavaScript files can save a bunch of load time, especially on mobile devices.

I’ve been playing about with this today and was quite happily using jsmin as described here until I noticed that in IE 7 and IE 8 the minified CSS didn’t work.

The problem seems to be when using a background style, it takes out the space between the image url close bracket and the next style.

background:url(image.png) no-repeat;
background:url(image.png)no-repeat;

Not a problem in IE 9 or chrome (haven’t tested others).

So I set about researching the problem and found nothing…struggled a bit getting the search term right and clearly never mastered it as I found zip.

Not to be put off, I was looking at the YUI compression tool from Yahoo, said to be better…but needs the java runtime and seems to complex to simply use, certainly for my simple taste!

Then I found a YUI .net implementation on codeplex.  Excellent, its was even in NuGet.

However…I wanted it as a build task to run in VS, I don’t really want to think about this stuff more than once.

So I wrote a little command line wrapper for it.  Excellent.  Even got ILMerge involved to merge the YUI dll’s into my exe.  I know there are ways to use Reflection to load dll’s as embedded resources…but I didn’t fancy doing that!

I did look at using CommandLine (also on codeplex) as I have done before, but ILMerge does not like that.  Don’t take my word for it, but it seems to be something to do with ILMerge is .net 2 and CommandLine uses some .net4 features.  It wasn’t happy…anyway, I just wrote a few lines of code to parse the command line args myself.

Perfect!!!

It’s not complex or very flexible, but is very suitable to my needs.

You can pass in an array of files to minify and a target path.  That’s it.  It’ll merge the files if you pass more than one…you have no choice!

> SCmin.exe –s C:\big.css C:\big1.css –t C:\small.css

// This will take big.css and big1.css and put it into small.css

Simples!

Download the exe or full source.

  

Posted On Saturday, December 3, 2011 3:52 AM | Comments (0)

Tuesday, November 22, 2011 #

Visual Web Part as a Sandboxed solution

You want the RAD wonderfulness of a visual web part, but it needs to be deployed as a Sandboxed solution.
Problem?
No, SharePoint powertools for visual studio to the rescue!
 
 
There are a couple limitations, read the above page, nothing major. e.g.
1. Javascript debugging is not supported
2. Debugging asp.net code is not supported.
3. Use of <% Assembly Src= is not supported
 
I understand it does it by adding the markup as an embedded resource, but I haven't actually tried it yet!  To come!
 

Posted On Tuesday, November 22, 2011 2:03 AM | Comments (0)

Monday, July 4, 2011 #

jQuery Mobile…is it ready???

I hope you haven’t come here looking for an answer!!! Because I want one too!!!

I have recently been playing with JQM…and initially loved it….but….

I mean, jQuery mobile is fantastic...whats been done here I think is awesome.  I'm enjoying working with it.

(I know its beta 1!, but the below seems odd for even a beta release)

There seems to be some fundamental bugs knocking about.  Links for example.  I have a fixed footer toolbar...3 buttons, Home, New, Settings.

Home - I wanted to be non-ajax, so I set data-ajax=false ( I need that page to be refreshed from the server each time its hit - I'm sure I could do something better - but I'm working on a POC)...In the browser it works as expected.  Go to the iPhone (added to Home Screen) hit that button and a new safari window opens?

New - This is an ajax true page, but doesn't always work...sometimes it goes to the new page, sometimes it goes to another page.

Back - rarely works as expected.

To be honest - links in general I find a little ropey...

Form Post - This seems to struggle with consistency...9/10 times it works a treat, then occasionally the loading icon just spins and it continues does so for a long while...too long to wait.  To be fair, this could be a drop in the iPhone wifi connection for whatever reason - I'm not sure anyway that form posting is the best solution for a mobile device targeted app...but like i said...POC :)

It's probably worth saying I am using asp.net mvc 3.  Each jQuery mobile page is in a separate Action and View...I haven't (except 1 dialog) got more than 1 page in each file.

The reason I posted this thread is really to raise my concerns and to get feedback from the community...I'm looking at a reasonable project coming my way and I make heavy use of jQuery so this seems natural to me...but I don't want to realise I've made a bad decision in 2 months time and need to start again???

Perhaps its just not ready….and that’s fine...but I don't want to realise I've made a bad decision in 2 months time and need to start again???

I'd also like to add...Window Phone 7...is NOT fully supported.  Tested on HTC

Posted On Monday, July 4, 2011 9:53 AM | Comments (1)

Monday, March 7, 2011 #

SharePoint 2010 Sandboxed solution SPGridView

If you didn’t know, you probably will soon, the SPGridView is not available in Sandboxed solutions.

To be honest there doesn’t seem to be a great deal of information out there about the whys and what nots, basically its not part of the Sandbox SharePoint API.

Of course the error message from SharePoint is about as useful as punch in the face…

An unexpected error has been encountered in this Web Part.  Error: A Web Part or Web Form Control on this Page cannot be displayed or imported. You don't have Add and Customize Pages permissions required to perform this action

…that’s if you have debug=true set, if not the classic “This webpart cannot be added” !! Love that one!

but will a little digging you should find something like this…

[TypeLoadException: Could not load  type Microsoft.SharePoint.WebControls.SPGridView from assembly 'Microsoft.SharePoint, Version=14.900.0.0, Culture=neutral, PublicKeyToken=71e9bce111e9429c'.]

 

Depending on what you want to do with the SPGridView, this may not help at all.  But I’m looking to inherit the theme of the site and style it accordingly.

After spending a bit of time with Chrome’s FireBug I was able to get the required CSS classes.  I created my own class inheriting from GridView (note the lack of a preceding SP!) and simply set the styles in there.

Inherit from the standard GridView

  1. public class PSGridView : GridView

 

Set the styles in the contructor…

  1. public PSGridView()
  2. {
  3.     this.CellPadding = 2;
  4.     this.CellSpacing = 0;
  5.     this.GridLines = GridLines.None;
  6.     this.CssClass = "ms-listviewtable";
  7.     this.Attributes.Add("style", "border-bottom-style: none; border-right-style: none; width: 100%; border-collapse: collapse; border-top-style: none; border-left-style: none;");
  8.  
  9.     this.HeaderStyle.CssClass = "ms-viewheadertr";
  10.     
  11.     this.RowStyle.CssClass = "ms-itmhover";
  12.     this.SelectedRowStyle.CssClass = "s4-itm-selected";
  13.     this.RowStyle.Height = new Unit(25);
  14. }

 

Then as you cant override the Columns property setter, a custom method to add the column and set the style…

  1. public void AddColumn(DataControlField field)
  2. {
  3.     if (field == null) return;
  4.  
  5.     field.ItemStyle.CssClass = "ms-vb2";
  6.     field.HeaderStyle.CssClass = "ms-vh2-nofilter ms-vh2-gridview";
  7.     this.Columns.Add(field);
  8. }

And that should be enough to get the nicely styled SPGridView without the need for the SPGridView, but seriously….get the SPGridView in the SandBox!!!

 

Posted On Monday, March 7, 2011 10:56 AM | Comments (5)

Saturday, March 5, 2011 #

jQuery Datatable in MVC … extended.

There are a million plugins for jQuery and when a web forms developer like myself works in MVC making use of them is par-for-the-course!  MVC is the way now, web forms are but a memory!!

Grids / tables are my focus at the moment.  I don’t want to get in to righting reems of css and html, but it’s not acceptable to simply dump a table on the screen, functionality like sorting, paging, fixed header and perhaps filtering are expected behaviour.  What isn’t always required though is the massive functionality like editing etc you get with many grid plugins out there.

You potentially spend a long time getting everything hooked together when you just don’t need it.

That is where the jQuery DataTable plugin comes in.  It doesn’t have editing “out of the box” (you can add other plugins as you require to achieve such functionality).

What it does though is very nicely format a table (and integrate with jQuery UI) without needing to hook up and Async actions etc. 

Take a look here… http://www.datatables.net

I did in the first instance start looking at the Telerik MVC grid control – I’m a fan of Telerik controls and if you are developing an in-house of open source app you get the MVC stuff for free…nice!  Their grid however is far more than I require. 

Note: Using Telerik MVC controls with your own jQuery and jQuery UI does come with some hurdles, mainly to do with the order in which all your jQuery is executing – I won’t cover that here though – mainly because I don’t have a clear answer on the best way to solve it!

One nice thing about the dataTable above is how easy it is to extend http://www.datatables.net/examples/plug-ins/plugin_api.html and there are some nifty examples on the site already…

I however have a requirement that wasn’t on the site … I need a grid at the bottom of the page that will size automatically to the bottom of the page and be scrollable if required within its own space i.e. everything above the grid didn’t scroll as well.  Now a CSS master may have a great solution to this … I’m not that master and so didn’t! The content above the grid can vary so any kind of fixed positioning is out.

So I wrote a little extension for the DataTable, hooked that up to the document.ready event and window.resize event.

Initialising my dataTable ( s )…

  1. $(document).ready(function () {
  2.     var dTable = $(".tdata").dataTable({
  3.         "bPaginate": false,
  4.         "bLengthChange": false,
  5.         "bFilter": true,
  6.         "bSort": true,
  7.         "bInfo": false,
  8.         "bAutoWidth": true,
  9.         "sScrollY": "400px"
  10.     });

My extension to the API to give me the resizing….

 

  1. // **********************************************************************
  2. // jQuery dataTable API extension to resize grid and adjust column sizes
  3. //
  4. $.fn.dataTableExt.oApi.fnSetHeightToBottom = function (oSettings) {
  5.     var id = oSettings.nTable.id;
  6.     var dt = $("#" + id);
  7.     var top = dt.position().top;
  8.     var winHeight = $(document).height();
  9.     var remain = (winHeight - top) - 83;
  10.     dt.parent().attr("style", "overflow-x: auto; overflow-y: auto; height: " + remain + "px;");
  11.     this.fnAdjustColumnSizing();
  12. }

 

This is very much is debug mode, so pretty verbose at the moment – I’ll tidy that up later!

You can see the last call is a call to an existing method, as the columns are fixed and that normally involves so CSS voodoo, a call to adjust those sizes is required.

Just above is the style that the dataTable gives the grid wrapper div, I got that from some firebug action and stick in my new height.

The –83 is to give me the space at the bottom i require for fixed footer!

 

Finally I hook that up to the load and window resize.  I’m actually using jQuery UI tabs as well, so I’ve got that in the open event of the tabs.

 

  1. $(document).ready(function () {
  2.         var oTable;
  3.         $("#tabs").tabs({
  4.             "show": function (event, ui) {
  5.                 oTable = $('div.dataTables_scrollBody>table.tdata', ui.panel).dataTable();
  6.                 if (oTable.length > 0) {
  7.                     oTable.fnSetHeightToBottom();
  8.                 }
  9.             }
  10.         });
  11.         $(window).bind("resize", function () {
  12.             oTable.fnSetHeightToBottom();
  13.         });
  14.     });

And that all there is too it.  Testament to the wonders of jQuery and the immense community surrounding it – to which I am extremely grateful.

I’ve also hooked up some custom column filtering on the grid – pretty normal stuff though – you can get what you need for that from their website.  I do hide the out of the box filter input as I wanted column specific, you need filtering turned on when initialising to get it to work and that input come with it!  Tip: fnFilter is the method you want.  With column index as a param – I used data tags to simply that one.

Posted On Saturday, March 5, 2011 3:58 PM | Comments (0)

Copyright © Steve Clements

Design by Bartosz Brzezinski

Design by Phil Haack Based On A Design By Bartosz Brzezinski