question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Programmatically toggle resources

See original GitHub issue

Looking through the issues I do not see this mentioned it anywhere, but it would be nice if you could programatically toggle a resource. This would probably work by either giving a resource ID to toggle just one or giving no ID to toggle all resources. Below is my proposal formatted like the docs.

toggleResource

Toggles a resource between the open/closed state.

.fullCalendar( 'toggleResource' [, idOrFilter [, state]] )

This method will toggle one or many resources between the opened/closed state depending on the filter and state parameter.

If idOrFilter is omitted, all resources will be toggled.

If idOrFilter is an ID, all resources with the same ID will be toggled.

idOrFilter may also be a filter function that accepts one Resource Object argument and returns true if it should be included in the result set.

State accepts two options, open and close, this will force the resources to either open or close.

Issue Analytics

  • State:open
  • Created 7 years ago
  • Reactions:13
  • Comments:11 (8 by maintainers)

github_iconTop GitHub Comments

2reactions
AlexanderWestencommented, Aug 26, 2021

I just wrote a little function using fullcalendar api and the internal state to set the expanded state of all resources that met a certain criteria based in the resources extendedProps.

You can also get the current isExpanded state somewhere from the currentDataManager in the fullcalendarApi if needed.

function setResourcesExpanded(expanded = false, filterValue = null) {
  const calendarApi = this.getCalendarApi();

  // get all current resources from resource store
  const resourcesObject = calendarApi.currentData.resourceStore;

  if (resourcesObject) {
    // resources are stored as an object
    Object.values(resourcesObject).forEach((resource) => {
      if (
        filterValue === null ||
        (resource.extendedProps &&
          resource.extendedProps.mySpecialProp === filterValue)
      ) {
        // using the fullcalendar dispatcher to toggle
        calendarApi.currentDataManager.dispatch({
          type: "SET_RESOURCE_ENTITY_EXPANDED",
          id: resource.id,
          isExpanded: expanded,
        });
      }
    });
  }
}

Code is working fullcalendar/vue 5.9.0

1reaction
arshawcommented, Feb 17, 2017

You may be able to get better performance if you using batchRows/unbatchRows (internal functions) to defer dimension readjustment until the very end:

function toggleRows(calendarElement, callback) {
    var view = calendarElement.data('fullCalendar').view;
    var resourceRows = view.resourceRowHash;

    view.batchRows();

    for(var resourceId in resourceRows) {
        var row = resourceRows[resourceId];

        if(callback(row, resourceId))
            row.toggleExpanded();
    }


    view.unbatchRows();
}
Read more comments on GitHub >

github_iconTop Results From Across the Web

C# WPF Switch Resource Programmatically - Stack Overflow
I want to define which key from the resourcedictionary is taken when the dialog popups up. something like customdialog.text = Message1; but ...
Read more >
How to switch among the resource files programmatically
In website, i want make localization where user can choose his favorite language, i add many resources files for many languages.
Read more >
Interact programmatically with the Navigation component
Create a NavHostFragment · Reference a destination using NavBackStackEntry · Share UI-related data between destinations with ViewModel · Modifying ...
Read more >
Toggle checkbox programmatically - MDBootstrap
The checkbox doesn't get checked or unchecked even if it's v-model changes. Resources (screenshots, code snippets etc.) <template> <mdb-input type ...
Read more >
Native UI Controls - Core Topics
Checkbox and Toggle Menu Items ; label, The label text to be displayed, A valid string resource or String ; subLabel, The sub-label...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found