【问题标题】:Telerik Extensions for ASP.NET MVC - GRID - randomly sorted items inside group in Chrome when GridOperationMode.ClientTelerik Extensions for ASP.NET MVC - GRID - 当 GridOperationMode.Client 时,Chrome 中组内的项目随机排序
【发布时间】:2015-03-14 14:08:34
【问题描述】:

数据源包含许多记录,但每12条记录代表1个实体的12个特征,按固定顺序排序。然后将行按 3 列(按“AccountName”、“OportunityName”和“OpportunityId”)分组,最深层次的组包含这 12 个特征。使用“GridOperationMode.Server”时一切正常:

但为了提高性能,我们决定将操作模式更改为客户端 - 'GridOperationMode.Client'。在那之后性能变得更好,但是这 12 个特征丢失了它们在 Chrome 中进行排序 - 对于每个组,它们以随机顺序呈现。我检查了 IE 和 FF 中的问题 - 发现他们没有这样的问题。任何想法如何修复 chrome 中的错误顺序?

使用 GridOperationMode.Client 时 Chrome 中的顺序错误

JS(缩短) - 绑定网格:

function populateForecastClosedGrid(controllerActionUrl) {
    var gridForecastClosed = $("#gridFORECASTREPORT").data("tGrid");
    var accountId = $('#accountsFilterCombo').data('tComboBox').value();
    gridForecastClosed.ajax.selectUrl = controllerActionUrl + '?checkDate=' + new Date().formatMMDDYYYY() + '&accountId=' + accountId;
    gridForecastClosed.showBusy();
    $.post(gridForecastClosed.ajax.selectUrl, function (data) {
        gridForecastClosed.dataSource.data([]);;
        gridForecastClosed.dataBind(data);
    });
}

网格(缩短):


    @(Html.Telerik().Grid()
          .Name("gridFORECASTREPORT")
          .Columns(列 => { ... }
          .DataKeys(keys => keys.Add(c => c.OpportunityId))
          .DataBinding(dataBinding => dataBinding.Ajax().OperationMode(GridOperationMode.Client))
          .Groupable(分组 => 分组。Groups(组 =>
          {
              groups.Add(c => c.AccountName);
              groups.Add(c => c.OpportunityName);
              groups.Add(c => c.OpportunityId);
          }).可见(假))
          .EnableCustomBinding(true)
          .Pageable(p => p.PageSize(396)))

【问题讨论】:

    标签: asp.net telerik telerik-grid telerik-mvc


    【解决方案1】:

    经过大量研究,我决定自己使用 JS 实现排序。 页面大小等于我的网格使用的 396 时,工作速度很快,当然可以做得更快。这些链接的 12 个项目中的每一个都在这 12 个项目组中具有正确顺序的字段 SortOrder。又快又脏,尽情享受吧!如果您知道更好的解决方案,请分享。到目前为止标记为已回答。真正有效的解决方案,经过我的 TL 批准,没有找到其他方法,可以适应任何其他网格。

    function onGridForecastClosedDataBound() {
        var grid = $(this).data('tGrid');
        // Request came to increase Forecast (Closed) grid performance. The only way (w/o touching SQL)
        // I found is to change grid operation mode from Server to GridOperationMode.Client (~50% increase).
        // But Telerik Grid + Chrome (OK on IE, FF) has a problem - wrong sorted items inside group
        // when grouping is performed on client side. This is a quick and dirty workaround for this
        // particular grid - to perform "sorting" manually using JS.
        // IMPORTANT! Pay attention, that if you change number of rows per
        // opportunity (currently 12) then the grid will be broken w/o changing the code below.
        if ('@Request.Browser.Browser' == 'Chrome') {
            var numberOfRowsPerOpportunity = 12;
    
            var rows = grid.$tbody.find('tr');
            var rowsSorted = [];
    
            while (rows.length > 0) {
                var partGroups = rows.splice(0, rows.slice(0, grid.groups.length).filter('.t-grouping-row').length);
                var partRows = rows.splice(0, numberOfRowsPerOpportunity);
                partRows.sort(function (a, b) {
                    var sortOrderA = parseInt($(a).find('td.sort-order').text());
                    var sortOrderB = parseInt($(b).find('td.sort-order').text());
                    return sortOrderA - sortOrderB;
                });
    
                $.each(partRows, function (index, item) {
                    $(item).removeClass('t-alt');
                    if (index % 2 != 0) $(item).addClass('t-alt');
                });
    
                $.merge(rowsSorted, partGroups);
                $.merge(rowsSorted, partRows);
            }
            rows.remove();
            grid.$tbody.append(rowsSorted);
        }
        grid.hideBusy();
    }
    
    function populateForecastClosedGrid(controllerActionUrl) {
        var gridForecastClosed = $("#gridFORECASTREPORT").data("tGrid");
        var accountId = $('#accountsFilterCombo').data('tComboBox').value();
        gridForecastClosed.ajax.selectUrl = controllerActionUrl + '?checkDate=' + new Date().formatMMDDYYYY() + '&accountId=' + accountId;
        gridForecastClosed.showBusy();
        gridForecastClosed.dataSource.data([]);
        gridForecastClosed.ajaxRequest();
    }
    

    网格(缩短):

    @(Html.Telerik().Grid<mForecastReport>()
          .Name("gridFORECASTREPORT")
          .DataKeys(keys => keys.Add(c => c.OpportunityId))
          .ClientEvents(e => e.OnDataBound("onGridForecastClosedDataBound"))
          .DataBinding(dataBinding => dataBinding.Ajax().OperationMode(GridOperationMode.Client))
          .Columns(columns => {
              ...
              columns.Bound(c => c.SortOrder).Hidden(true).HtmlAttributes(new {  @class = "sort-order" });
          }
          .Groupable(grouping => grouping.Groups(groups => 
          {
              groups.Add(c => c.AccountName);
              groups.Add(c => c.OpportunityName);
              groups.Add(c => c.OpportunityId);
          }).Visible(false))
          .Pageable(p => p.PageSize(396)))
    

    【讨论】:

      猜你喜欢
      • 2011-01-29
      • 1970-01-01
      • 2023-03-07
      • 1970-01-01
      • 2017-02-21
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多