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



大家好,

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

列表如下:

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

这里是剑道网格代码:

@(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))
)

改变元素列表顺序之前的Kendo UI网格列图像

更改列表顺序后的图像

所以,我可以在改变列表的顺序后根据列表元素重新排序网格列吗?

如果有人能迅速回答,那就更有帮助了。

谢谢,

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

  1. 首先你必须将网格的reorderable设置为true

    。Reorderable(reorder => reorder. columns (true))

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

  • 在list change事件中以编程方式重新排序列:

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

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

    最新更新