It would be nice if the "link" type allowed you to pass in optional formatterParams that you could override the default text or href data.
This would help for when you want the text to be shorter and readable, but the link is long and doesn't make sense to actually have in the table.
Hey @sellersj
You are in luck, the link editor is getting an overhaul in next months release :)
Cheers
Oli
Hey @sellersj
you will be happy to hear i have just pushed some updates for the link formatter to the 3.4 branch, there are now a number of additional formatterParams you can pass with the link formatter to change the way it displays:
Set label from another field in the table:
{title:"Link", field:"url", formatter:"link", formatterParams:{labelField:"url_label"}},
Set label from another string or callback
{title:"Link", field:"url", formatter:"link", formatterParams:{label:"Click Here"}},
{title:"Link", field:"url", formatter:"link", formatterParams:{label:function(cell){return "Click for " + cell.getData().title}}},
Set url from another field in the table:
{title:"Link", field:"url_label", formatter:"link", formatterParams:{urlField:"url"}},
Set url from another string or callback
{title:"Link", field:"url_label", formatter:"link", formatterParams:{url:"http://www.google.com"}},
{title:"Link", field:"url_label", formatter:"link", formatterParams:{url:function(cell){return "http://" + cell.getData().url}}},
These will be included in the 3.4 offical release in a couple of weeks time.
Cheers
Oli :)
Tabulator version 3.4 has now been officially released!
You can find details of the new release in the News Section
Full documentation of all the new features can be found Here
Cheers
Oli :)
This was great! Thanks for your hard work.
Ideal, to be "plug and play", is a kind of URI template instead of formatterParams:{url:myURL}. For example:
{title:"Link1", field:"url_label1", link-template:"http://www.google.com"},
{title:"Link2", field:"url_label2", link-template:"http://{url}"},
{title:"Link3", field:"url_label3", link-template:"/otherPage/{cellName1}/{cellName2}"}
Implementation: when a field specification have link-template, it must be pre-parsed, to expand into formatter:"link" and formatterParams:{url: procLinkTemplate(cell,link_template_input)}. The function of procLinkTemplate() can be calculated by simple str.replace(pattern, function () { ... }), or a loop like:
function procLinkTemplate(cell,s0){ // s0 is the link_template_input
const r = RegExp('\{([^\}]*)\}', 'g');
let s = '';
let a;
let idx=0
while ((a = r.exec(s0)) !== null) {
s += ( s0.substring(idx, r.lastIndex-a[0].length) + (cell.getData())[a[1]] )
idx = r.lastIndex
}
if ( idx<s0.length ) s+=s0.substring(idx,s0.length)
return s
}
PS: need a new enhance-issue, suggesting "friendly link"?
Most helpful comment
Hey @sellersj
You are in luck, the link editor is getting an overhaul in next months release :)
Cheers
Oli