dhxpyt.pagination

1from .pagination import Pagination
2from .pagination_config import PaginationConfig
3
4__all__ = [
5    'Pagination',
6    'PaginationConfig'
7]
class Pagination:
14class Pagination:
15    def __init__(self, config: PaginationConfig = None, widget_parent: str = None):
16        """
17        Initializes the Pagination widget.
18
19        :param config: (Required) The PaginationConfig object containing the pagination configuration.
20        :param widget_parent: (Optional) The ID of the HTML element where the pagination will be attached.
21        """
22        if config is None:
23            raise ValueError("PaginationConfig is required for initializing Pagination widget.")
24        config_dict = config.to_dict()
25        # Assuming that `config.data` is a DHTMLX DataCollection instance
26        # We need to handle data initialization appropriately
27        # For now, we will pass the data collection directly
28
29        # Create the Pagination instance
30        self.pagination = js.dhx.Pagination.new(widget_parent, js.JSON.parse(json.dumps(config_dict)))
31
32    """ Pagination API Functions """
33
34    def destructor(self) -> None:
35        """Destroys the Pagination instance and releases resources."""
36        self.pagination.destructor()
37
38    def get_page(self) -> int:
39        """Returns the index of the active page."""
40        return self.pagination.getPage()
41
42    def get_pages_count(self) -> int:
43        """Gets the total number of pages in the pagination."""
44        return self.pagination.getPagesCount()
45
46    def get_page_size(self) -> int:
47        """Returns the number of items displayed per page."""
48        return self.pagination.getPageSize()
49
50    def set_page(self, page: int) -> None:
51        """Sets an active page in the related widget."""
52        self.pagination.setPage(page)
53
54    def set_page_size(self, size: int) -> None:
55        """Sets the number of items displayed on a page."""
56        self.pagination.setPageSize(size)
57
58    """ Pagination Event Handlers """
59
60    def add_event_handler(self, event_name: str, handler: Callable) -> None:
61        """Adds an event handler for the specified event."""
62        event_proxy = create_proxy(handler)
63        self.pagination.events.on(event_name, event_proxy)
64
65    def on_change(self, handler: Callable[[int, int], None]) -> None:
66        """Fires on changing the active page."""
67        def event_handler(index, previousIndex):
68            handler(index, previousIndex)
69        self.pagination.events.on('change', create_proxy(event_handler))
Pagination( config: PaginationConfig = None, widget_parent: str = None)
15    def __init__(self, config: PaginationConfig = None, widget_parent: str = None):
16        """
17        Initializes the Pagination widget.
18
19        :param config: (Required) The PaginationConfig object containing the pagination configuration.
20        :param widget_parent: (Optional) The ID of the HTML element where the pagination will be attached.
21        """
22        if config is None:
23            raise ValueError("PaginationConfig is required for initializing Pagination widget.")
24        config_dict = config.to_dict()
25        # Assuming that `config.data` is a DHTMLX DataCollection instance
26        # We need to handle data initialization appropriately
27        # For now, we will pass the data collection directly
28
29        # Create the Pagination instance
30        self.pagination = js.dhx.Pagination.new(widget_parent, js.JSON.parse(json.dumps(config_dict)))

Initializes the Pagination widget.

Parameters
  • config: (Required) The PaginationConfig object containing the pagination configuration.
  • widget_parent: (Optional) The ID of the HTML element where the pagination will be attached.
pagination

Pagination API Functions

def destructor(self) -> None:
34    def destructor(self) -> None:
35        """Destroys the Pagination instance and releases resources."""
36        self.pagination.destructor()

Destroys the Pagination instance and releases resources.

def get_page(self) -> int:
38    def get_page(self) -> int:
39        """Returns the index of the active page."""
40        return self.pagination.getPage()

Returns the index of the active page.

def get_pages_count(self) -> int:
42    def get_pages_count(self) -> int:
43        """Gets the total number of pages in the pagination."""
44        return self.pagination.getPagesCount()

Gets the total number of pages in the pagination.

def get_page_size(self) -> int:
46    def get_page_size(self) -> int:
47        """Returns the number of items displayed per page."""
48        return self.pagination.getPageSize()

Returns the number of items displayed per page.

def set_page(self, page: int) -> None:
50    def set_page(self, page: int) -> None:
51        """Sets an active page in the related widget."""
52        self.pagination.setPage(page)

Sets an active page in the related widget.

def set_page_size(self, size: int) -> None:
54    def set_page_size(self, size: int) -> None:
55        """Sets the number of items displayed on a page."""
56        self.pagination.setPageSize(size)

Sets the number of items displayed on a page.

def add_event_handler(self, event_name: str, handler: Callable) -> None:
60    def add_event_handler(self, event_name: str, handler: Callable) -> None:
61        """Adds an event handler for the specified event."""
62        event_proxy = create_proxy(handler)
63        self.pagination.events.on(event_name, event_proxy)

Adds an event handler for the specified event.

def on_change(self, handler: Callable[[int, int], NoneType]) -> None:
65    def on_change(self, handler: Callable[[int, int], None]) -> None:
66        """Fires on changing the active page."""
67        def event_handler(index, previousIndex):
68            handler(index, previousIndex)
69        self.pagination.events.on('change', create_proxy(event_handler))

Fires on changing the active page.

class PaginationConfig:
 6class PaginationConfig:
 7    """
 8    Configuration class for the Pagination widget.
 9    """
10    def __init__(self,
11                 data: Any,  # Should be a DataCollection instance from DHTMLX library
12                 css: str = None,
13                 inputWidth: int = 40,
14                 page: int = 0,
15                 pageSize: int = 10):
16        """
17        Initializes the PaginationConfig.
18
19        :param data: (Required) The data collection of a widget to set into the pagination.
20        :param css: (Optional) Adds style classes to the pagination.
21        :param inputWidth: (Optional) Sets the width for the input of the pagination.
22        :param page: (Optional) The index of the initial page set in the pagination.
23        :param pageSize: (Optional) The number of items displayed per page of the related widget.
24        """
25        self.data = data
26        self.css = css
27        self.inputWidth = inputWidth
28        self.page = page
29        self.pageSize = pageSize
30
31    def to_dict(self) -> Dict[str, Any]:
32        """
33        Converts the PaginationConfig into a dictionary format.
34        """
35        config_dict = {
36            'data': self.data,
37            'css': self.css,
38            'inputWidth': self.inputWidth,
39            'page': self.page,
40            'pageSize': self.pageSize,
41        }
42        # Remove None values
43        return {k: v for k, v in config_dict.items() if v is not None}

Configuration class for the Pagination widget.

PaginationConfig( data: Any, css: str = None, inputWidth: int = 40, page: int = 0, pageSize: int = 10)
10    def __init__(self,
11                 data: Any,  # Should be a DataCollection instance from DHTMLX library
12                 css: str = None,
13                 inputWidth: int = 40,
14                 page: int = 0,
15                 pageSize: int = 10):
16        """
17        Initializes the PaginationConfig.
18
19        :param data: (Required) The data collection of a widget to set into the pagination.
20        :param css: (Optional) Adds style classes to the pagination.
21        :param inputWidth: (Optional) Sets the width for the input of the pagination.
22        :param page: (Optional) The index of the initial page set in the pagination.
23        :param pageSize: (Optional) The number of items displayed per page of the related widget.
24        """
25        self.data = data
26        self.css = css
27        self.inputWidth = inputWidth
28        self.page = page
29        self.pageSize = pageSize

Initializes the PaginationConfig.

Parameters
  • data: (Required) The data collection of a widget to set into the pagination.
  • css: (Optional) Adds style classes to the pagination.
  • inputWidth: (Optional) Sets the width for the input of the pagination.
  • page: (Optional) The index of the initial page set in the pagination.
  • pageSize: (Optional) The number of items displayed per page of the related widget.
data
css
inputWidth
page
pageSize
def to_dict(self) -> Dict[str, Any]:
31    def to_dict(self) -> Dict[str, Any]:
32        """
33        Converts the PaginationConfig into a dictionary format.
34        """
35        config_dict = {
36            'data': self.data,
37            'css': self.css,
38            'inputWidth': self.inputWidth,
39            'page': self.page,
40            'pageSize': self.pageSize,
41        }
42        # Remove None values
43        return {k: v for k, v in config_dict.items() if v is not None}

Converts the PaginationConfig into a dictionary format.