Created
December 28, 2012 19:23
-
-
Save stlsmiths/4401054 to your computer and use it in GitHub Desktop.
YUI3 DT column formatter for HTML "link"
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
This assumes you have "data" with the following "keys" defined, | |
customer_id, customer_name, carrier_name, carrier_id | |
It defines an HTML template as the base link HTML and uses a | |
YUI3 substitution function (Y.Lang.sub) to safely replace the | |
tokens within the htmlTMPL. | |
You must have "allowHTML:true" set for this to work properly. | |
Use in columns as; | |
{ key : "customer_name", | |
label : "Customer", | |
sortable : true, | |
// resizeable : true, // not supported in YUI3 at this time! | |
// maxAutoWidth : 200, // not supported in YUI3 at this time! | |
formatter : formatLinkYUI3, | |
allowHTML:true | |
} | |
Likewise the configuration for column "carrier_name" would be similar | |
**/ | |
function formatLinkYUI3(o) { | |
var colkey = o.column.key || o.column.name, | |
htmlTMPL = '<a href="{href}">{linkText}</a><br/><br/>', | |
cellHTML = ''; | |
switch(colkey) { | |
case 'customer_name' : | |
cellHTML = Y.Lang.sub(htmlTMPL,{ | |
href: '/admin/editcustomer.do?customerId=' + o.record.get('customer_id'), | |
linkText: o.value | |
}); | |
break; | |
case 'carrier_name': | |
cellHTML = Y.Lang.sub(htmlTMPL,{ | |
href: '/nsp/editcarrier.do?carrierId=' + o.record.get('carrier_id'), | |
linkText: o.value | |
}); | |
break; | |
default: | |
cellHTML = 'Unknown column key'; | |
} | |
return cellHTML; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment