user348173
user348173

Reputation: 9288

jqGrid: Added one extra group for grouping

I want to add grouping to my jqGrid. I have a simple model:

public class ViolationViewModel
{       
    [JqGridColumnFormatter(JqGridColumnPredefinedFormatters.Date, SourceFormat = "d.m.Y H:i:s", OutputFormat = "d.m.Y H:i")]
    public DateTime FixationTime { get; set; }       
    public string OrderNumber { get; set; }
    public string ViolationType { get; set; }
}

This is code in a view:

@{
      var grid = new JqGridHelper<ViolationViewModel>("myGrid",
      dataType: JqGridDataTypes.Json,
      methodType: JqGridMethodTypes.Post,
      pager: true,
      sortingName: "ViolationType",
      sortingOrder: JqGridSortingOrders.Asc,
      url: Url.Action("Violation", "Cabinet"),
      viewRecords: true,
      rowsList: new List<int>() { 10, 20, 30, 50, 100 },
      loadOnce: true,
      multiSelect: true,
      autoWidth: true,
      groupingEnabled: true,
      groupingView: new JqGridGroupingView { ColumnShow = new[] { false }, Fields = new[] { "ViolationType" }, DataSorted = true},         
    ).FilterToolbar(new JqGridFilterToolbarOptions() { StringResult = true })
    .Navigator(new JqGridNavigatorOptions() { Add = false, Delete = false, Edit = false, View = false, Refresh = false, Search = false });

}

I have 16 records, 15 records with the same ViolationType, 1 record have other value .

The problem with that jqGrid create three (must be two) groups, but there are two groups have the same caption. But when I click on any column (change sort) then all works fine and I have two groups.

Where is a problem?

One more question: in the rowList option I have the first value as 10. But when my grid is loaded default value is 20. How to setup it to first value?

Upvotes: 0

Views: 568

Answers (1)

tpeczek
tpeczek

Reputation: 24125

You have set DataSorted to true. In this case the data from the initial request should be already properly sorted (by 'ViolationType') on the server side and returned in proper order.

For the second part of your question, just set rowsNumber to 10 for intial value:

@{
    var grid = new JqGridHelper<ViolationViewModel>("myGrid",
        dataType: JqGridDataTypes.Json,
        methodType: JqGridMethodTypes.Post,
        pager: true,
        sortingName: "ViolationType",
        sortingOrder: JqGridSortingOrders.Asc,
        url: Url.Action("Violation", "Cabinet"),
        viewRecords: true,
        rowsList: new List<int>() { 10, 20, 30, 50, 100 },
        rowsNumber: 10,
        loadOnce: true,
        multiSelect: true,
        autoWidth: true,
        groupingEnabled: true,
        groupingView: new JqGridGroupingView { ColumnShow = new[] { false }, Fields = new[] { "ViolationType" }, DataSorted = true},         
    )
    .FilterToolbar(new JqGridFilterToolbarOptions() { StringResult = true })
    .Navigator(new JqGridNavigatorOptions() { Add = false, Delete = false, Edit = false, View = false, Refresh = false, Search = false });
}

Upvotes: 1

Related Questions