일 | 월 | 화 | 수 | 목 | 금 | 토 |
---|---|---|---|---|---|---|
1 | 2 | |||||
3 | 4 | 5 | 6 | 7 | 8 | 9 |
10 | 11 | 12 | 13 | 14 | 15 | 16 |
17 | 18 | 19 | 20 | 21 | 22 | 23 |
24 | 25 | 26 | 27 | 28 | 29 | 30 |
- CSV
- 가로 스크롤 막대
- MYSQL
- Oracle
- chart.js
- swift 화면전환
- 세로 스크롤 막대
- 일본여행
- MS-SQL
- 썸머노트
- league of legends
- 한글깨짐
- Banker's
- .csv
- 나만의 상점
- Excel
- Kakao API Address
- Request.Form
- Aspose.cells
- 초딩수학
- upbit
- Android
- 스크롤 사라짐
- 업비트
- rounding
- Banker's rounding
- MSSQL
- LEFT JOIN
- 시트 탭 사라짐
- python
- Today
- Total
DBA
Dev Extreme Data Grid Data Binding - @model, Mvc(), WebApi() 본문
Dev Extreme Data Grid Data Binding - @model, Mvc(), WebApi()
코볼 2023. 1. 6. 15:20@model
Index.cshtml
----------------------------------------------------------------------------------------------------------------------------
@model List<DevExtremeMvcApp1.Models.PGT_FactSalesQuotaResult>
@(Html.DevExtreme().DataGrid()
.ID("gridContainerModel")
.DataSource(Model)
.KeyExpr("SalesQuotaKey")
.ShowBorders(true)
.Columns(c =>
{
c.Add().DataField("SalesQuotaKey");
c.Add().DataField("Title");
c.Add().DataField("Date");
c.Add().DataField("SalesAmountQuota");
})
)
----------------------------------------------------------------------------------------------------------------------------
PivotGridController.cs
----------------------------------------------------------------------------------------------------------------------------
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
// using 추가 - Models
using DevExtremeMvcApp1.Models;
namespace DevExtremeMvcApp1.Controllers
{
public class PivotGridController : Controller
{
// GET: PivotGrid
public ActionResult Index()
{
List<PGT_FactSalesQuotaResult> result;
using(PGTDataContext PGT = new PGTDataContext())
{
result = PGT.PGT_FactSalesQuota(2011).ToList();
}
return View(result);
}
}
}
----------------------------------------------------------------------------------------------------------------------------
Mvc() 이용 :
Index.cshtml
----------------------------------------------------------------------------------------------------------------------------
@using DevExtremeMvcApp1.Models
@(Html.DevExtreme().DataGrid<PGT_FactSalesQuotaResult>()
.ID("gridContainer")
.DataSource(d => d.Mvc().Controller("PivotGrid").LoadAction("PivotGridList").LoadParams(new { calendarYear = 9999 }))
.ShowBorders(true)
.Columns(c =>
{
c.AddFor(m => m.SalesQuotaKey).Width(150);
c.AddFor(m => m.Title).Width(150);
c.AddFor(m => m.Date).Width(150);
c.AddFor(m => m.SalesAmountQuota).Width(150);
})
)
----------------------------------------------------------------------------------------------------------------------------
PivotGridController.cs
----------------------------------------------------------------------------------------------------------------------------
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
// using 추가 - Models, Newtonsoft.Json
using DevExtremeMvcApp1.Models;
using Newtonsoft.Json;
namespace DevExtremeMvcApp1.Controllers
{
public class PivotGridController : Controller
{
// GET: PivotGrid
public ActionResult PivotGridList(short? calendarYear)
{
if (calendarYear == 9999)
{
calendarYear = null;
}
List<PGT_FactSalesQuotaResult> result;
using (PGTDataContext PGT = new PGTDataContext())
{
result = PGT.PGT_FactSalesQuota(calendarYear).ToList();
}
var resultJson = JsonConvert.SerializeObject(result);
return Content(resultJson, "application/json");
}
}
}
----------------------------------------------------------------------------------------------------------------------------
WebApi() 이용 :
Index.cshtml
----------------------------------------------------------------------------------------------------------------------------
@using DevExtremeMvcApp1.Models
@(Html.DevExtreme().DataGrid<PGT_FactSalesQuotaResult>()
.ID("gridContainerApi")
.DataSource(d => d.WebApi().Controller("PivotGridApi").LoadAction("PivotGridList").LoadParams(new { calendarYear = 9999 }))
.ShowBorders(true)
.Columns(c =>
{
c.AddFor(m => m.SalesQuotaKey).Width(150);
c.AddFor(m => m.Title).Width(150);
c.AddFor(m => m.Date).Width(150);
c.AddFor(m => m.SalesAmountQuota).Width(150);
})
)
----------------------------------------------------------------------------------------------------------------------------
PivotGridApiController.cs - Api Controller를 추가 해야 함.
----------------------------------------------------------------------------------------------------------------------------
using System;
using System.Collections.Generic;
using System.Linq;
using System.Net;
using System.Net.Http;
using System.Web.Http;
// using 추가 - Models, DevExtreme.AspNet.Data, DevExtreme.AspNet.Mvc
using DevExtreme.AspNet.Data;
using DevExtreme.AspNet.Mvc;
using DevExtremeMvcApp1.Models;
namespace DevExtremeMvcApp1.Controllers
{
public class PivotGridApiController : ApiController
{
[HttpGet]
public HttpResponseMessage PivotGridList(short? calendarYear, DataSourceLoadOptions loadOptions)
{
if (calendarYear == 9999)
{
calendarYear = null;
}
List<PGT_FactSalesQuotaResult> result;
using (PGTDataContext PGT = new PGTDataContext())
{
result = PGT.PGT_FactSalesQuota(calendarYear).ToList();
}
return Request.CreateResponse(DataSourceLoader.Load(result, loadOptions));
}
}
}
----------------------------------------------------------------------------------------------------------------------------