0

클라이언트 쪽 페이징을 피하기 위해 컨트롤러에서 검도 그리드의 페이지 인덱스를 설정하려고합니다. 클라이언트 쪽 페이징을 사용하면 첫 페이지의 레코드 외에 다른 레코드가 표시되지 않습니다. 컨트롤러에서 데이터를 호출 할 때 페이지에 필요한 10 개의 레코드 만 반환합니다. 데이터 호출에는 Skip() 및 Take() 함수가 포함되어 전체 그리드를로드하는 대신 서버에서 필요로하는 것을 반환합니다.Kendo UI 그리드 페이지 인덱스를 MVC 컨트롤러로 설정하십시오.

.cshtml

@(Html.Kendo().Grid<Reckon.Service.Payroll.Data.DTO.EmployeeDto>() 
     .Name("EmployeeGrid") 
     .Columns(cols => 
     { 
       cols.Bound(emp => emp.Id).Title("ID").Hidden(); 
       cols.Bound(emp => emp.EmployeeNumber).Title("Employee ID").Width(100); 
       cols.Bound(emp => emp.IsPayRunReady).Title("Status").Width(10).ClientTemplate("<span title='This employee is #= IsPayRunReady ? '': 'not '#payrun ready.' class='#= IsPayRunReady ? 'okICN-small' : 'alertICN-small'#'>#= IsPayRunReady ? '': 'Not' # #= IsPayRunReady ? 'P':'p'#ayrun ready</span>"); 
       cols.Bound(emp => emp.FirstName).Title("First Name").Width(100); 
       cols.Bound(emp => emp.LastName).Title("Last Name").Width(100); 
       cols.Bound(emp => emp.DateOfBirth).Title("DOB").Format("{0:dd/MM/yyyy}").Width(100); 
       cols.Template(@<text></text>).ClientTemplate("<a href='" + Url.Action("EmployeeDetailEdit", "EmployeeDetail") + "/#=Id#'>Edit</a>").Width(50); 
       cols.Template(@<text></text>).ClientTemplate("<a href='" + Url.Action("EmployeeDetailRead", "EmployeeDetailRead") + "/#=Id#'>View</a>").Width(50); 
       cols.Template(@<text></text>).ClientTemplate("<a class='k-button xxx' tag='#=Id#'>Delete</a>").Width(50); 
     }) 
      .Pageable(pageable => pageable.ButtonCount(5)) 
      .Sortable(sortable => sortable.AllowUnsort(false)) 
      .Filterable() 
      .Resizable(resize => resize.Columns(true)) 
      .Reorderable(reorder => reorder.Columns(true)) 
      .Navigatable() 
      .Events(evt => evt.DataBound("afterGridLoaded")) 
      .DataSource(dataSource => dataSource 
            .Ajax() 
            .Batch(true) 
            .PageSize(10) 
            .ServerOperation(false) 
            .Model(model => 
            { 
             model.Id(emp => emp.Id); 
            }) 
            .Read(read => read.Action("EmployeeListPerPage", "EmployeeDetail")) 
            ) 
    ) 

.cs

public ActionResult EmployeeListPerPage([DataSourceRequest] DataSourceRequest request) 
    { 
     Dispose(); 
     EmployeeListRequest empList = new EmployeeListRequest(); 
     empList.PageNum = request.Page; 
     empList.PageSize = request.PageSize; 
     //empList.OrderBy = null; //request.Sorts.Any() ? "EmployeeNumber" : request.Sorts[0].Member; 

     var dataSource = _payrollService.GetEmployeeListPerPage(empList); 
     var model = new EmployeeListModel(dataSource); 

     DataSourceResult result = model.Employees.ToDataSourceResult(request); 
     result.Total = dataSource.Total;    

     // Set the Page index here 

     return Json(result, JsonRequestBehavior.AllowGet);    
    } 

클라이언트 측 페이징을 이용하면, 첫 번째 페이지로 리턴 데이터를 설정하고 복귀 클라이언트 측 페이징을 수행 결과가 없습니다.

할 수 있습니까? 도움을 주시면 대단히 감사하겠습니다. 당신이 엔티티 프레임 워크, 검도/EF 페이징을 돌볼 수 있도록 이에 대한 컨트롤러를 변경 사용하고 있기 때문에

+0

어떤 이유로 당신은 검도의 페이징을 사용하고 싶지 않습니까? –

+0

검도 페이징은 클라이언트 쪽이며 서버 쪽에서 데이터가 반환되면 현재 페이지에 필요한 10 개의 레코드 만 반환합니다. 레코드는 첫 번째 10 레코드로 그리드에 바인딩되며 첫 페이지 이외의 다른 페이지를 클릭하면 다른 레코드가 표시되지 않습니다. 그래서 모든 데이터를 그리드로 반환하지 않고 현재 선택한 페이지에 필요한 데이터 만 반환하기 때문에 검도 페이징을 사용하고 싶지 않습니다. –

+0

왜 이렇게하려고하는지 이해가 안됩니다.'empList.PageNum = request.Page;'Kendo가 자동으로 수행하는 작업과 본질적으로 다른 작업을하고 있습니다. 쿼리 문자열을 통해 페이지를 방문하면 적절한 페이지가 반환됩니다. –

답변

1

(이것은 서버 측이됩니다) :

거친 예입니다
public ActionResult EmployeeList([DataSourceRequest] DataSourceRequest request) 
{ 
    var employees = from emp in dbContext.Employees 
        select emp; 

    return Json(employees.ToDataSourceResult(request), JsonRequestBehavior. 
} 

,하지만해야 출발점.

+0

안녕하세요 @ millillican, 전 위의 방법을 시도했지만 전체 데이터 세트를 반환하고 현재 작업중인 테이블에는 1 백만 개가 넘는 레코드가 있습니다. 서버가 모든 서버 페이지에 대한 모든 레코드를 가져 오거나 시작시 한 번만 가져 오게하면 서버에서 많은로드가 발생합니다. 그래서 현재 페이지 세부 정보 만 한 번에로드해야합니다. –

+0

@pchannon - 그러면 EF가 올바르지 않은 것 같습니다. 실행을 연기하고 해당 페이지에 필요한 결과 만 되돌려 야합니다. –