📜  jQWidgets jqxScheduler ensureVisible() 方法(1)

📅  最后修改于: 2023-12-03 15:02:20.784000             🧑  作者: Mango

jQWidgets jqxScheduler's ensureVisible() Method

jqxScheduler is a powerful and customizable jQuery-based scheduler with support for various features such as multiple views, recurring events, resources, and locales. The ensureVisible() method is a key functionality provided by the jqxScheduler API which helps to ensure that the specified date or resource is visible in the scheduler viewport.

Method Signature
ensureVisible(date: Date | string, resourceId?: any)
Parameters
  • date: A Date object or a string in a format recognized by the Date.parse method. Represents the date to be ensured visible in the scheduler.
  • resourceId: (Optional) A string or a number representing the ID of the resource to be ensured visible in the scheduler.
Return Value

This method doesn't return any value.

Example
// get the jQWidgets jqxScheduler instance
var scheduler = $('#scheduler').jqxScheduler('getInstance');

// ensure that the current date (today) is visible in the scheduler
scheduler.ensureVisible(new Date());

// ensure that a particular date is visible in the scheduler
scheduler.ensureVisible('2021-09-25');

// ensure that a particular resource is visible in the scheduler
scheduler.ensureVisible(new Date(), 'resource-1');
How It Works

When ensureVisible() is called with a valid date parameter, the method calculates the position of the date in the scheduler viewport and adjusts the viewport accordingly. If the resourceId parameter is also specified, the method calculates the position of the resource in the scheduler and adjusts the viewport.

Internally, the ensureVisible() method uses the scrollTo() method to adjust the scheduler viewport position. The scrollTo() method is a built-in method of the jqxScrollBars class, which is used by the jqxScheduler component to handle scrolling. When the scrollTo() method is called with a valid position parameter, it updates the scrollbar position and adjusts the viewport position accordingly.

Conclusion

The ensureVisible() method provided by jqxScheduler is a useful feature that helps you ensure that a particular date or resource is visible in the scheduler viewport. This method is particularly useful when you need to programmatically navigate to a specific date or resource in the scheduler.