getState

returns the reactive state object of Document Manager

object getState();
objectstate object

Example

// returns the current state of File manager
const state = $$("fm").getState();
 
// switches the widget to the "cards" view 
state.mode = "cards";

Related samples

Details

The returned state object contains the following properties and methods:

{
  mode: "grid",
  selectedItem: [],
  search: "",
  path: "/",
  source: "files",
  clipboard: null
}

Properties

  • mode (string) - set the currently/initially visible tab. Possible values are "list" (default), "cards" and "double"
  • path (string) - sets the currently/initially opened folder within "My files"
  • source - stores the current group folder ID ("files" - stands for "My files", "trash", "favorite", "recent" or "shared"); if source is not "files", path can be only "/"
  • selectedItem (array) - stores array of selected items (objects)
  • search (string) - stores text from the search input
  • clipboard (object) - stores clipboard data, e.g. { files: [{date: dateValue, id: "/Data.xlsx", size: 55215, type: "document", value: "Data.xlsx"}], mode: "copy"}.

Methods

  • $observe (function) - a handler to listen to changes in the current state of Document Manager. It takes 2 parameters:
    • prop (string) - a reactive property to listen changes of
    • handler (function) - a function to execute when changes are made. It takes the only argument:
      • value (any) - the current value of the reactive property. The type of the value (string, array, etc) depends on a reactive property being observed.
  • batch (function)- allows to set several properties at once. Takes the only parameter:
    • props (object) - an object containing the pairs of the property name and the value to set.

For example, you can listen to the source changes as:

state.$observe("source", id => 
    $$("sources").setValue(`The current source is "${id}"`));
);

Or set several properties in a batch:

// switches to the "cards" view and clears the search field
state.$batch({
   mode:"cards", search:""
});
Back to top