In general the process is very, very easy:
- Construct a DataTable for the data
- Fill it with the data you want (for example, retrieved from an external RSS-Feed)
- Give the DataTable to the DataTableDataSource...
- ...and that's it
Download this Demo-App to give it a try, or look at the result here.
Code Sample
@using System.Data
@using ToSic.Eav.DataSources
@functions
{
// Official place to provide data preparation. Is automatically called by 2SexyContent
public override void CustomizeData()
{
var res = CreateResourcesSource();
res.Source.Rows.Add(1031, "de-de", "Deutsch", "Herzlich Willkommen", "Schön, dass Sie dies lesen, bitte haben Sie Spass!", "Vorname", "Nachname");
res.Source.Rows.Add(1033, "en-us", "English", "Welcome", "Thanks for looking at this!", "First name", "Last name");
Data.In.Add(res.ContentType, res.Out["Default"]);
// enable publishing
Data.Publish.Enabled = true;
Data.Publish.Streams = "Default,UIResources";
}
private DataTableDataSource CreateResourcesSource()
{
var dataTable = new DataTable();
dataTable.Columns.AddRange(new[]
{
new DataColumn("EntityId", typeof(int)),
new DataColumn("EntityTitle"),
new DataColumn("Language"),
new DataColumn("Title"),
new DataColumn("Introduction"),
new DataColumn("FirstNameLabel"),
new DataColumn("LastNameLabel")
});
var source = CreateSource<DataTableDataSource>();
source.Source = dataTable;
source.ContentType = "UIResources";
//source.TitleField = "FullName"; // not necessary because we're already using the default
//source.EntityIdField = "EntityId";// not necessary because we're already using the default
return source;
}
}
<div class="sc-element">
@Content.Toolbar
<h1>Simple Demo with custom data (for example to use non-SQL data)</h1>
<p>This demo uses the 2sxc Pipeline (req. 2sxc 6.0.6+). More info <a href="http://2sexycontent.org/en-us/docsmanuals/feature.aspx?feature=2580" target="_blank">here</a>.</p>
<h2>These entities resources are constructed by code</h2>
<ol>
@foreach (var resource in AsDynamic(Data.In["UIResources"]))
{
//var resource = AsDynamic(eRes);
<li>@resource.EntityTitle - @resource.Title</li>
}
</ol>
</div>