根据元素列表的顺序重新排序 Kendo UI 网格列

问题描述 投票:0回答:1

美好的一天,

我有一个包含元素的列表,根据该列表将获得网格。我需要更改该列表中元素的顺序。因此,当我更改列表的顺序并运行报告时,网格将按照之前列表的顺序获取,而不是按照新更改的顺序获取。

这是列表:

@Html.ListBox("multiselect_to", Model.AvailableColumnsList, new { @class = "form-control bdr_rad_3", size = "8", multiple = "multiple" })

这是 Kendo Grid 代码:

@(Html.Kendo().Grid<Entrada.CustomerPortal.UI.Models.JobReport>()
.Name("JobReportGrid")
  .ToolBar(tools => tools.Pdf())
  .Pdf(pdf => pdf
  .AllPages()
  .FileName("Kendo UI Grid Export.pdf")
  .ProxyURL(Url.Action("Excel_Export_Save", "JobReports")))
  .ToolBar(tools => tools.Excel())
  .Excel(excel => excel
  .AllPages(true)
  .FileName("Kendo UI Grid Export.xlsx")
  .ProxyURL(Url.Action("Excel_Export_Save", "JobReports")))
  .ColumnMenu()
  .Columns(columns =>
  {
    columns.Bound(p => p.JobNumber)//.Title("Job <br/> Number")
        .Width(colWidth["Job Number"])
        .ClientTemplate("<a class='jobReportGridJN' jnum='#=JobNumber#'>" + "#=JobNumber#" + "</a>"+
    @" #if(STAT== true) {#  <span><img src='" + Url.Content("~/Images/stat-icon.png") + "'> </span>#}#");

    columns.Bound(p => p.DictatorID);
    columns.Bound(p => p.JobType);//.Title("Job <br/> Type");
    columns.Bound(p => p.DeviceGenerated)//.Title("Device <br/> Generated")
        .Width(colWidth["Device Generated"]);
    columns.Bound(p => p.AppointmentDate)//.Title("Appointment <br/> Date")
        .Width(colWidth["Appointment Date"])
        .Format(colFormat["Appointment Date"]);
    columns.Bound(p => p.InProcess)//.Title("In <br/> Process")
        .Width(colWidth["In Process"])
        .Format(colFormat["In Process"]);
    columns.Bound(p => p.EditingComplete)
        .Width(colWidth["Editing Complete"])
        .Format(colFormat["Editing Complete"]);
    columns.Bound(p => p.JobStatus);//.Title("Job <br/> Status");
    columns.Bound(p => p.MRN);
    columns.Bound(p => p.Patient);
  })
  .Groupable()
  .Selectable(selectable => selectable
  .Mode(GridSelectionMode.Single)
  .Type(GridSelectionType.Row))
  .DataSource(dataSource => dataSource
    .Ajax()
    .Read(read => read
        .Action("JobSearchPaginationGrid", "JobReports")
        .Data("residentsReadData"))
    .Events(events => events.Error("error_handler"))
    .PageSize((int)ViewData["PageSize"])
    .Group(group => group.Add<string>((string)TempData["GridGroupBy"]))
    .ServerOperation(true)
    )
  .Pageable(pager => pager.Messages(Info => Info.Empty("No Results Found")))
  .Sortable()
  .Resizable(resize => resize.Columns(true))
  .Scrollable().Selectable(s => s.Mode(GridSelectionMode.Single).Type(GridSelectionType.Row))
)

Image for Kendo UI grid columns before changing the order of list of elements

Image for List after changing the order

那么,在更改列表顺序后,我可以根据该列表元素对网格列重新排序吗?

如果有人快速回答的话会更有帮助。

谢谢,

c# jquery kendo-asp.net-mvc kendo-ui-grid
1个回答
0
投票

我自己没有尝试过,但经过一分钟的谷歌搜索后,如果我理解正确的话,实现这一目标的过程似乎涉及两个步骤:

  1. 首先,您必须将网格的

    Reorderable
    设置为 true:

    .Reorderable(reorder => reorder.Columns(true))
    

    http://demos.telerik.com/aspnet-mvc/grid/column-reordering

  2. 在列表更改事件中以编程方式重新排序列:

    var grid = $("#JobReportGrid").data("kendoGrid");
    grid.reorderColumn(newOrderIndex, grid.columns[currentIndex]);
    

    http://docs.telerik.com/KENDO-UI/api/javascript/ui/grid#methods-reorderColumn

© www.soinside.com 2019 - 2024. All rights reserved.