Skip to main content

provide-data

Description

Allows parsing data to the File Manager widget

The action fires after the request-data action, namely, when the required folder ID (for which data is requested) is received. This action is not triggered for updates through the data property.

Usage

"provide-data": ({
data: [],
id: string
}) => boolean

Parameters

The callback of the provide-data action takes an object with the following parameters:

  • data - (required) an array with new data provided:
  • id (string) - the ID of an item
  • type (string) - (optional) the type which can be "file" or "folder"
  • size (number) - (optional) an item size in bytes
  • lazy (boolean) - (optional) when set to true for the "folder" items, indicates that their content needs to be requested separately
  • date (Date) - (optional) an item date
  • id (string) - (required) the ID of the parent of the provided folder (if any)

Example

<script>
import { Filemanager } from "wx-svelte-filemanager";

const server = "https://some-backend-url";

let api;

function loadData(ev) {
const id = ev.detail.id;
fetch(server + "/files?id=" + encodeURIComponent(id))
.then((data) => data.json())
.then((data) => api.exec("provide-data", { data, parent: id }));
}

let rawData = [];
$: {
fetch(server + "/files")
.then((data) => data.json())
.then((data) => (rawData = data));
}

</script>

<Filemanager
bind:api
data={rawData}
on:data-request={loadData}
//other settings />

Related articles: How to access File Manager API