Web Application
note
📣  The Symfony Boilerplate uses BootstrapVue as templating framework. However, most of the explanations from this chapter should work with most frameworks with little adjustments.
List Mixin#
The Symfony Boilerplate provides the List mixin. This mixin contains useful data and methods to help you build a list.
note
📣  A mixin content merges with the content of your Vue component.
Initialization#
The initialization of your page occurs in the asyncData attribute of your Vue Component:
note
📣  asyncData merges at runtime with the data of your Vue component.
note
📣  Don't use null as value for your scalar parameters as it will make your page reload. Prefer,
for instance, an empty string.
Fields / Headers#
You do that in the data attribute of your Vue component:
note
📣  The key value have to have the same name as the corresponding GraphQL field.
Data#
By default, the <b-table> component automatically renders the data thanks to its items and fields attributes.
However, you may want to customize the output. For instance:
Search#
There are two kinds of search:
- Live search.
- On click search.
First, you have to prepare your data:
note
📣  Don't use null as value for your scalar parameters as it will make your page reload. Prefer,
for instance, an empty string.
Live Search#
For <b-input type="text"> component, you should use both the :debounce and @update attributes:
note
📣  The default debounce value comes from the List mixin.
For <b-form-select> component, you should use the @change attribute:
On Click Search#
Search Logic#
The List mixin provides the onSearch method. It resets the current page to 1 and call the doSearch method.
You have to implement this last method:
Sort#
The browser could handle the sorting, but it does not make sense in the Symfony Boilerplate, as the API is able to handle this task for us.
Yet, we have to prepare the UI.
First let's start by updating the data:
note
📣  It is best to create a dedicated enum in src/webapp/enums/filters for sort by values.
Once the data is ready, we have to update the <b-table> component:
:no-local-sortingdisables browser-side sorting.:sort-byuses the computed valueboostrapTableSortByfrom theListmixin. This computed value uses itself oursortByMap.:sort-descuses the computed valueisDescfrom theListmixin.@sort-changeduses the methodonSortfrom theListmixin. This method sets thethis.sortByandthis.sortOrdervalues from the mixin, reset the current page to 1, before calling yourdoSearchmethod.
We may now update the asyncData and doSearch methods:
Paginate#
The <b-pagination> component is a great way to handle pagination for a list:
currentPageis a data from theListmixin.:per-pageuses theitemsPerPagedata from theListmixin. You may override its value in your component.:total-rowsuses thecountdata from theListmixin. You update this value in yourdoSearchmethod.@changeuses the methodonPaginatefrom theListmixin. It sets the current page and calls yourdoSearchmethod.@click.native="$scrollToTopcalls the pluginscrollToTopthat... scrolls to the top of the page when the user clicks on the pagination buttons.
Loading State#
:busydisplays a loader istrue. It uses theisLoadingdata from theListmixin.