|
[home.component.html]
<div id="Grid">
//use div element.
</div>
[home.component.ts]
export class HomeComponent {
public gridData:any;
public data: any;
public columns: any;
constructor(private http: Http) {
}
ngOnInit(): void {
this.gridData = new ej.DataManager({
url: "http://services.odata.org/V4/Northwind/Northwind.svc/Orders",
crossDomain: true,
adaptor: new ej.ODataV4Adaptor,
});
this.http.get('api/Orders').subscribe((data: any) => {
this.columns = [{ field: "OrderID" }];
$("#Grid").ejGrid({
dataSource: this.gridData,
allowPaging:true,
columns: this.columns,
});
});
}
|
|
<ej:Grid ID="OrdersGrid" runat="server" AllowPaging="True">
<ClientSideEvents Load="load" />
</ej:Grid>
<script type="text/javascript">
function load(args) {
var orderData = JSON.parse('<%= new System.Web.Script.Serialization.JavaScriptSerializer().Serialize(this.data)%>');
this.model.columns = orderData;
}
</script>
Serverside:-
public IEnumerable data;
List<Orders> order = new List<Orders>();
protected void Page_Load(object sender, EventArgs e){
if (cols.Count == 0) {
cols.Add(new Col() { field = "OrderID" });
cols.Add(new Col() { field = "EmployeeID" });
}
BindDataSource();
}
private void BindDataSource()
{
. . .
this.data = cols;
}
public static List<Col> cols = new List<Col>();
[Serializable]
public class Col
{
public Col()
{
}
public Col(string field)
{
this.field= field;
}
public string field { get; set; }
}
}
|