BoldSignEasily embed eSignatures in your .NET applications. Free sandbox with native SDK available.
I am following the answer from here:
https://www.syncfusion.com/kb/2465/how-to-display-array-of-strings-within-a-grid-column
, but trying to implement it for Core MVC:
<script type="text/x-jsrender" id="InterestsTemplate">
{{:~getVal(Cities,"name")}}
</script>
<ej-grid id="FlatGrid" datasource="ViewBag.DataSource">
<e-columns>
<e-column field="Name" header-text="Name"></e-column>
<e-column header-text="Cities" Template=true TemplateID="CitiesTemplate"></e-column>
</e-columns>
</ej-grid>
Data looks like this:
[{"name":"Name 1","cities":[{"name":"City 1"},{"name":"City2"},{"name":"City3"}]}]
or 1 row from table can have alot of cities, which I want to put to its cell.
<ej-grid id="FlatGrid" allow-paging="true" >
<e-datamanager url="/Home/DataSource" adaptor="UrlAdaptor"/>
<e-columns>
<e-column field="ID" header-text=ID" is-primary-key="true"width="75"></e-column>
<e-column field="FirstName " header-text="First Name"></e-column>
<e-column field="LastName " header-text="Last Name"></e-column>
<e-column field="Address " header-text="Address" template="true" template-id="#template" ></e-column>
</e-columns>
</ej-grid>
<script type="text/x-jsrender" id ="template">
{{for Addresses}}
<span>{{>Address1}}</span>
<span>{{>Address2}}</span><br />
{{/for}}
</script>
Serverside:-
List<Person> Persons = new List<Person>();
protected void Page_Load(object sender, EventArgs e)
{
BindDataSource();
}
private void BindDataSource()
{
List<Address> adrs1 = new List<Address>();
adrs1.Add(new Address() { Address1 = "No: 417", Address2 = "1st street", City = "Aurora", Country = "Arapahoe", Zip = "80010" });
. . .
List<Address> adrs2 = new List<Address>();
adrs2.Add(new Address() { Address1 = "No: 378", Address2 = "3rd cross street", City = "Austin", Country = "Travis", Zip = "78701" });
. . .
List<Address> adrs3 = new List<Address>();
adrs3.Add(new Address() { Address1 = "No: 195", Address2 = "7th golden street", City = "Sandy", Country = "Salt Lake", Zip = "84070" });
Persons.Add(new Person() { ID = 1001, FirstName = "John", LastName = "Beckett", Addresses = adrs1 });
Persons.Add(new Person() { ID = 1002, FirstName = "Ben", LastName = "Smith", Addresses = adrs2 });
Persons.Add(new Person() { ID = 1003, FirstName = "Andrew", LastName = "Fuller", Addresses = adrs3 });
this.Grid.DataSource = Persons;
this.Grid.DataBind();
}
[Serializable]
public class Person
{
public Person()
{
}
public Person(int id, string firstName, string lastName, List<Address> address)
{
this.ID = id;
this.FirstName = firstName;
this.LastName = lastName;
this.Addresses = address;
}
public int ID { get; set; }
public string FirstName { get; set; }
public string LastName { get; set; }
public List<Address> Addresses { get; set; }
}
[Serializable]
public class Address
{
public string Address1 { get; set; }
public string Address2 { get; set; }
public string City { get; set; }
public string Country { get; set; }
public string Zip { get; set; }
}
} |