fbaligand / kibana-enhanced-table

Kibana visualization like a Data Table, but with enhanced features like computed columns, filter bar, and “Split Cols” bucket
Apache License 2.0
305 stars 65 forks source link

How can we have an option for showing a link or not #260

Closed tracylucky closed 2 years ago

tracylucky commented 2 years ago

Hi guys,

Thanks for your great plugin.

I'd like to add a column, if the content contains http/https, there will be clickable link. But if the content doesn't have the http/https words, it should not be a link, just show the text. could you please give me some help, how can I make it work, thanks a lot

tracylucky commented 2 years ago
image
fbaligand commented 2 years ago

Hi,

I tested exactly the formula you give and it works fine for me. I use enhanced-table v1.13.0 with Kibana 7.17.0.

But it should work for a lot of versions, this is not a new feature. That said, what is your Kibana version and plugin version?

Then, given that you generate html in your formula, you should not use "template" feature, especially since it escapes html chars like < and >. By the way, given the screenshot of your settings, you can't get the result on the left: link label should be "aaa" and value could not be displayed as a link, because template escapes html special chars.

If you really want to use "template", you can display value without html escaping, using this syntax: {{{value}}}

tracylucky commented 2 years ago

Thanks for your prompt reply, what my exact formula is indexOf(col6, "https")> -1?" " + col6 + "":col6, if I don't use 'template', how can it work to me? Thanks a lot.

image
fbaligand commented 2 years ago

OK, with real formula, I understand better now. So the problem is that "+" does not concatenation (like in javascript). To do concatenation, you have to use || operator. So I invite you to replace all + by ||.

To find documentation on Formula syntax, you can click on "documentation" link above "Formula" field. Then click on "expr-eval" link. You will find there all information about expr-eval syntax (that is the syntax used by Formula).

tracylucky commented 2 years ago

Thanks, it works. Another question is how can I adjust the column width? now it seems automatically change, but it is not good to view

image
fbaligand commented 2 years ago

You can use "Cell computed CSS", with something like: "width: 10%"

But I strongly recommend you to use as link label, either a static value either a column reference that is short.

fbaligand commented 2 years ago

You can eventually try “min-width” and “max-width” CSS attributes

tracylucky commented 2 years ago

Hi @fbaligand one more question, how can we have 'filter for the value' for a link, thanks

image
fbaligand commented 2 years ago

Well, the only way to have "Filter for value" that works on a computed column, is to have a Formula with a simple reference to a classic column (ex: col1), and then use a template to render the value as a html link (ex: <a href="https://www.google.com?q={{value}}">link</a>.

tracylucky commented 2 years ago

My formula is a little complicated `_indexOf(col9, "https")> -1?" < a href='" || col9 || "' target='blank'>click me</ a>":col9, so that is impossible to have the 'Filter for value'?

fbaligand commented 2 years ago

Yes, in that case, it will not work. Sorry. Because in you case, the cell value will be your computed as a html block, and filtering requires that cell "value" is the filter value.

fbaligand commented 2 years ago

As question is answered, I close the issue.