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 MixinThe 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.
#
InitializationThe 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 / HeadersYou 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.
#
DataBy 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:
#
SearchThere 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 SearchFor <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 LogicThe 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:
#
SortThe 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-sorting
disables browser-side sorting.:sort-by
uses the computed valueboostrapTableSortBy
from theList
mixin. This computed value uses itself oursortByMap
.:sort-desc
uses the computed valueisDesc
from theList
mixin.@sort-changed
uses the methodonSort
from theList
mixin. This method sets thethis.sortBy
andthis.sortOrder
values from the mixin, reset the current page to 1, before calling yourdoSearch
method.
We may now update the asyncData
and doSearch
methods:
#
PaginateThe <b-pagination>
component is a great way to handle pagination for a list:
currentPage
is a data from theList
mixin.:per-page
uses theitemsPerPage
data from theList
mixin. You may override its value in your component.:total-rows
uses thecount
data from theList
mixin. You update this value in yourdoSearch
method.@change
uses the methodonPaginate
from theList
mixin. It sets the current page and calls yourdoSearch
method.@click.native="$scrollToTop
calls the pluginscrollToTop
that... scrolls to the top of the page when the user clicks on the pagination buttons.
#
Loading State:busy
displays a loader istrue
. It uses theisLoading
data from theList
mixin.