Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

for format type "link", allow seperate text from href #800

Closed
sellersj opened this issue Dec 27, 2017 · 5 comments
Closed

for format type "link", allow seperate text from href #800

sellersj opened this issue Dec 27, 2017 · 5 comments
Assignees
Labels
Enhancement Possible small update to an existing feature Question - Ask On Stack Overflow Questions must be asked on Stack Overflow

Comments

@sellersj
Copy link

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.

@olifolkerd olifolkerd self-assigned this Dec 28, 2017
@olifolkerd olifolkerd added Enhancement Possible small update to an existing feature Question - Ask On Stack Overflow Questions must be asked on Stack Overflow labels Dec 28, 2017
@olifolkerd
Copy link
Owner

Hey @sellersj

You are in luck, the link editor is getting an overhaul in next months release :)

Cheers

Oli

@olifolkerd
Copy link
Owner

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 :)

@olifolkerd
Copy link
Owner

olifolkerd commented Feb 12, 2018

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 :)

@sellersj
Copy link
Author

This was great! Thanks for your hard work.

@ppKrauss
Copy link

ppKrauss commented Jul 24, 2020

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"?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Enhancement Possible small update to an existing feature Question - Ask On Stack Overflow Questions must be asked on Stack Overflow
Projects
None yet
Development

No branches or pull requests

3 participants