dataedit icon indicating copy to clipboard operation
dataedit copied to clipboard

✨[Feature Request] Add support for dataviewjs syntax

Open soumendrak opened this issue 1 year ago • 2 comments

Thanks for this awesome budding plugin. If dataviewjs syntax also can be supported it will be further useful. A sample dataviewjs script for notes created/modified today:

// default dateformat in case it’s forgotten in front matter
var dateformat = "YYYY-MM-DD";
if (dv.current().dateformat) { dateformat = dv.current().dateformat; }

dv.table(["File", "LastModifiedOn", "CreatedOn"],
  dv.pages()
  .where(p => p.file.mday.equals(dv.current().file.day) || p.file.cday.equals(dv.current().file.day))
  .sort(p => p.file.mtime, 'asc')
  .map(p => [
    p.file.link,
    moment(p.file.mtime.toString()).format(dateformat),
    moment(p.file.ctime.toString()).format(dateformat),
  ])
);

soumendrak avatar May 27 '24 15:05 soumendrak

Dataviewjs is supported

Instead of doing dv.table(headers, values) just return an object with keys for headers and values

Let me know if the following doesn't work :) Note I am unsure about the dateformat being respected as I hadn't considered that.

// default dateformat in case it’s forgotten in front matter
var dateformat = "YYYY-MM-DD";
if (dv.current().dateformat) { dateformat = dv.current().dateformat; }

return{
  headers: ["File", "LastModifiedOn", "CreatedOn"],
  values:
  dv.pages()
  .where(p => p.file.mday.equals(dv.current().file.day) || p.file.cday.equals(dv.current().file.day))
  .sort(p => p.file.mtime, 'asc')
  .map(p => [
    p.file.link,
    moment(p.file.mtime.toString()).format(dateformat),
    moment(p.file.ctime.toString()).format(dateformat),
  ])
};

unxok avatar May 28 '24 01:05 unxok

I had tested the given code and the console shows the error as follow. PixPin_2025-01-04_10_27_00

It seems that "dv.current()" is not support. We could check it by "console.log" command in dataedit code block.

console.log( dv.current() )

fornewfork avatar Jan 04 '25 02:01 fornewfork