Custom Dynamic DataSources - Use in Visual Query
Requirements
Query using Authors and KeepOdd
The following query will simply combine the two DataSources. The first will provide the authors. The second will apply the KeepOdd filters.
Query with Configuration
DataSources which have [Configuration]
attributes can also support full visual configuration.
The system looks for a content type with the same name as the DataSource + Configuration.
In this case, it's looking for a Content Type WithConfigConfiguration
.
Data in the Query (7)
- Hello from WithConfig #1 - Favorite Color: burgundy
- Hello from WithConfig #2 - Favorite Color: burgundy
- Hello from WithConfig #3 - Favorite Color: burgundy
- Hello from WithConfig #4 - Favorite Color: burgundy
- Hello from WithConfig #5 - Favorite Color: burgundy
- Hello from WithConfig #6 - Favorite Color: burgundy
- Hello from WithConfig #7 - Favorite Color: burgundy
Visual Query Customizations
Many aspects such as the Icon, Name etc. have automatic defaults.
But you can configure them as you need using the [VisualQuery]
attribute.
Source Code of this file
Below you'll see the source code of the file. Note that we're just showing the main part, and hiding some parts of the file which are not relevant for understanding the essentials. Click to expand the code
@inherits Custom.Hybrid.Razor14 @using ToSic.Razor.Blade; @using System.Linq; @using ToSic.Eav.DataSources; <!-- unimportant stuff, hidden --> <h2>Custom Dynamic DataSources - Use in Visual Query</h2> <div @Sys.PageParts.InfoWrapper()> @Html.Partial("../shared/DefaultInfoSection.cshtml") <div @Sys.PageParts.InfoIntro()> <p> Dynamic DataSources can also be used in Queries. The following examples show how to use them. </p> <div class="row"> <div class="col-4">@Sys.Fancybox.PreviewWithLightbox(App.Path + "/data-sources/assets/app-data-sources.jpg", 200, 100, "float-left", label: "Dynamic DataSources in Visual Query")</div> </div> </div> </div> Query using Authors and KeepOdd The... <!-- unimportant stuff, hidden --> <div class="row"> <div class="col-4">@Sys.Fancybox.PreviewWithLightbox(App.Path + "/data-sources/assets/use-in-visual-query.jpg", 200, 100, "float-right float-end", label: "Simple Query", figure: false)</div> </div> @{ var queryOddAuthors = Kit.Data.GetQuery("DynamicDataSourceKeepOdd"); } <h3>Data in the Query (@queryOddAuthors.List.Count())</h3> <ul> @foreach (var item in AsList(queryOddAuthors)) { <li> <strong>@item.EntityTitle</strong> (ID: @item.EntityId) </li> } </ul> Query with Configuration DataSources... <!-- unimportant stuff, hidden --> <div class="row"> <div class="col-4">@Sys.Fancybox.PreviewWithLightbox(App.Path + "/data-sources/assets/configure-in-visual-query1.jpg", 200, 100, "float-left", label: "Configured Query", figure: false)</div> <div class="col-4">@Sys.Fancybox.PreviewWithLightbox(App.Path + "/data-sources/assets/configure-in-visual-query2.jpg", 200, 100, "float-left", label: "Edit Configuration", figure: false)</div> </div> @{ var queryWithConfig = Kit.Data.GetQuery("DynamicDataSourceWithConfig"); } <h3>Data in the Query (@queryWithConfig.List.Count())</h3> <ul> @foreach (var item in AsList(queryWithConfig)) { <li> <strong>@item.Title</strong> - Favorite Color: @item.FavoriteColor </li> } </ul> Visual Query Customizations Many aspects... <!-- unimportant stuff, hidden --> <div class="row"> <div class="col-4">@Sys.Fancybox.PreviewWithLightbox(App.Path + "/data-sources/assets/visual-query-attribute.jpg", 200, 200, "float-left", label: "Customized with VisualQuery Attribute", figure: false)</div> </div> @* Footer *@ @Html.Partial("../Shared/Layout/FooterWithSource.cshtml", new { Sys = Sys })