Skip to content

Commit 71c1aa6

Browse files
committed
Blazor movie tutorial QuickGrid styling
1 parent 2117fd2 commit 71c1aa6

File tree

2 files changed

+38
-2
lines changed

2 files changed

+38
-2
lines changed

aspnetcore/blazor/tutorials/movie-database-app/part-8.md

Lines changed: 38 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -118,11 +118,11 @@ Run the app and navigate to the movies `Index` page. You can page through the mo
118118

119119
The component is *interactive*. The page doesn't reload for paging to occur. The paging is performed live over the SignalR connection between the browser and the server, where the paging operation is performed on the server with the rendered result sent back to the client for the browser to display.
120120

121-
Change <xref:Microsoft.AspNetCore.Components.QuickGrid.PaginationState.ItemsPerPage%2A> to a more reasonable value, such as 10 items per page:
121+
Change <xref:Microsoft.AspNetCore.Components.QuickGrid.PaginationState.ItemsPerPage%2A> to a more reasonable value, such as five items per page:
122122

123123
```diff
124124
- private PaginationState pagination = new PaginationState { ItemsPerPage = 2 };
125-
+ private PaginationState pagination = new PaginationState { ItemsPerPage = 10 };
125+
+ private PaginationState pagination = new PaginationState { ItemsPerPage = 5 };
126126
```
127127

128128
## Sortable `QuickGrid`
@@ -199,6 +199,42 @@ Filtering database records is performed on the server, and the server interactiv
199199

200200
Instead of an HTML form, submitting a GET request in this scenario could've also used JavaScript to submit the request to the server, either using the [Fetch API](https://developer.mozilla.org/docs/Web/API/Fetch_API)` or [XMLHttpRequest API](https://developer.mozilla.org/docs/Web/API/XMLHttpRequest). In most cases, JavaScript can be replaced by using Blazor and C# in an interactive component.
201201

202+
## Style `QuickGrid` rows and cells
203+
204+
You can apply table row and cell styles to the rendered `QuickGrid` component with a stylesheet isolated to the `Index` component using *CSS isolation*.
205+
206+
CSS isolation only applies to the component you associate with the format `{COMPONENT NAME}.razor.css`, where the `{COMPONENT NAME}` placeholder is the component name. The filename is `Index.razor.css` to apply the isolated styles to the `Index` component.
207+
208+
To apply changes to a child component, such as the `QuickGrid` component of the `Index` component, use the `::deep` pseudo-element for element styles in the stylesheet. The `::deep` pseudo-element only works with descendant elements, so the `QuickGrid` component must be wrapped with a `<div>` in order to apply the styles to it.
209+
210+
In `Components/Pages/MoviePages/Index.razor`, place `<div>` tags around the `QuickGrid` component:
211+
212+
```diff
213+
+ <div>
214+
<QuickGrid ...>
215+
...
216+
</QuickGrid>
217+
+ </div>
218+
```
219+
220+
In the `MoviePages` folder, add a new isolated stylesheet for the `Index` component. Use `::deep` pseudo-elements to make the row height `3em` and vertically-center the table cell content.
221+
222+
`Components/Pages/MoviePages/Index.razor.css`:
223+
224+
```css
225+
::deep tr {
226+
height: 3em;
227+
}
228+
229+
::deep tr > td {
230+
vertical-align: middle;
231+
}
232+
```
233+
234+
Blazor rewrites CSS selectors to match the markup rendered by the component. The rewritten CSS styles are bundled and produced as a static asset for you, so you don't need to take further action to apply the styles to the `QuickGrid` component when it's rendered.
235+
236+
![Movie list showing row heights at 3em with vertically-centered content](~/blazor/tutorials/movie-database-app/part-8/_static/styled-quickgrid.png)
237+
202238
## Clean up
203239

204240
:::zone pivot="vs"
125 KB
Loading

0 commit comments

Comments
 (0)