Important

You are browsing the documentation for version 3.1 of OroCommerce, OroCRM and OroPlatform, which is no longer maintained. Read version 5.1 (the latest LTS version) of the Oro documentation to get up-to-date information.

See our Release Process documentation for more information on the currently supported and upcoming releases.

Dashboards

Create a Dashboard Widget

To display a list of tasks on the dashboard with most recent tasks first you basically have to perform three steps:

  1. Create a data grid that collects and displays the data of the tasks while making sure that most recent tasks are displayed on top.

  2. Create a Twig template that renders the grid.

  3. Finally, to write everything together, configure the dashboard widget by telling it which template to render.

Configuring the Grid

The data grid that will be displayed on the dashboard can be based upon the already existing app-tasks-grid that you used to show a grid of all the tasks being present. You just need to sort the result (the id can be used as a sorting criteria as more recent tasks will have higher ids):

1# src/AppBundle/Resources/config/oro/datagrids.yml
2datagrids:
3    # ...
4    app-recent-tasks-grid:
5        extends: app-tasks-grid
6        sorters:
7            default:
8                id: DESC

Widget Template

To actually render the data grid on the dashboard you need to create a Twig template that is based on the OroDashboardBundle:Dashboard:widget.html.twig template. To do so create a template named recent_tasks_widget.html.twig located in the Resources/views/Dashboard directory of your bundle (see Adding Widget Configuration for an explanation of the schema you should follow for the template name and location) with the following content:

 1{# src/AppBundle/Resources/views/Dashboard/recent_tasks_widget.html.twig #}
 2{% extends 'OroDashboardBundle:Dashboard:widget.html.twig' %}
 3{% import 'OroDataGridBundle::macros.html.twig' as dataGrid %}
 4
 5{% block content %}
 6    {{ dataGrid.renderGrid('app-recent-tasks-grid') }}
 7{% endblock %}
 8
 9{% block actions %}
10    {% set actions = [{
11        'url': path('app_task_index'),
12        'type': 'link',
13        'label': 'All tasks',
14    }] %}
15
16    {{ parent() }}
17{% endblock %}

Adding Widget Configuration

 1# src/AppBundle/Resources/config/oro/dashboards.yml
 2dashboards:
 3    widgets:
 4        recent_tasks:
 5            label: Recent Tasks
 6            route: oro_dashboard_widget
 7            route_parameters:
 8                bundle: AppBundle
 9                name: recent_tasks_widget
10            description: This widget displays the most recent tasks

The configured oro_dashboard_widget route refers to a controller action that comes as part of the Oro\Bundle\DashboardBundle\Controller\DashboardController and simply renders a template whose name is inferred from route parameters (the name of the template that the controller is looking for follows the {{bundle}}:Dashboard:{{name}} pattern where {{bundle}} and {{name}} refer to the route parameters of the dashboard config).

Tip

If your widget contains some more logic (e.g. calling some service and doing something with its result, you can create your own controller, configure a route for it, and then refer to this route with the route key in your widget configuration.