obsidian-dataview icon indicating copy to clipboard operation
obsidian-dataview copied to clipboard

Limit title length for more readable results

Open daamiian opened this issue 1 year ago • 3 comments

Is your feature request related to a problem? Please describe. I use long descriptive titles for my notes, like Andy Matuschack, so my dataview tables can get very long just for one row. Currently, my dataview tables are becoming unusable because of this - I have to scroll for ages on my laptop to see 10 results!

Describe the solution you'd like I'd love it if I could limit the characters of the file or field (sometimes I list file.inlinks, which gives the same problem as when the file itself is long, just in another column). This way, I can choose how much of the title is useful in a table, as apposed to a full sentence like all of my notes are formatted.

Describe alternatives you've considered I couldn't find any workarounds for this, but I'm interested in hearing one! I won't reduce the size of all of my filenames since it goes against my workflow of having links mentioned right in the body using natural language.

Additional context I also would love to be able to truncate in a similar way field values. Because as I mentioned, I often have files listed, and then the outgoing and incoming links to that file. So, I have a table that has files listed which are already long, then in the column beside it, I have the inlinks to that file (again very long titles), then in the next column, the outlinks (long titles). I need something that might give something like this:

|| File || Incoming Links || Outgoing Links || | Mice are often... | Allowing the c... | Notes containi...|

Where character limit is something I can set. Or some way to control these tables! Thank you for all of the work you do!

daamiian avatar Jul 20 '22 11:07 daamiian

There are two ways to get around it for now:

  • Display a substring of your file title either with string indexing like field[0:10] or with substring(). Not entirely sure that the indexing method works.
  • CSS to wrap the table cells by defining custom CSS class via YAML.

AB1908 avatar Jul 20 '22 12:07 AB1908

There are two ways to get around it for now:

* Display a substring of your file title either with string indexing like `field[0:10]` or with `substring()`. Not entirely sure that the indexing method works.

* CSS to wrap the table cells by defining custom CSS class via YAML.

Thanks for the reply, I'm not sure I understand what you mean with your first workaround. Can you use an example?

daamiian avatar Jul 20 '22 13:07 daamiian

  • substring("this is a field", 0, 10) == "this is a"
  • "this is a field"[0:4] == "this" (not entirely sure this works)

AB1908 avatar Jul 20 '22 18:07 AB1908

It's a bit clunky, but you can use the truncate function to shorten your files link:

TABLE WITHOUT ID link(file.path, truncate(file.name, 20))

You can do similar with long field values:

truncate(longval, 20)

TABLE WITHOUT ID link(file.path, truncate(file.name, 20)), truncate(longval, 20)
WHERE file = this.file

For inlinks, it would be something like:

map(file.outlinks, (x) => link(x, truncate(meta(x).path, 20)))

I hope that serves your use case. I'd like to close the issue if you're okay with that.

s-blu avatar Nov 15 '22 20:11 s-blu