일 | 월 | 화 | 수 | 목 | 금 | 토 |
---|---|---|---|---|---|---|
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 |
- httpclient timeout
- .csv
- MS-SQL
- 초딩수학
- 일본여행
- Kakao API Address
- swift 화면전환
- 아이코딩습관
- 블록코딩
- chart.js
- largelanguagemodels
- PromptEngineering
- 중학생코딩
- 썸머노트
- Excel
- Aspose.cells
- 오블완
- MYSQL
- 한글깨짐
- AIoptimization
- cc챔피언
- 중1코딩
- 엔트리
- python
- MSSQL
- ASP.NET MVC
- league of legends
- Android
- upbit
- 코딩입문
- 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));
}
}
}
----------------------------------------------------------------------------------------------------------------------------