multi-Level RowGroup

multi-Level RowGroup

eyal_hbeyal_hb Posts: 98Questions: 31Answers: 0

i am working with multi level rowgroup and i want to know if i can order other column without broke the regroup,
i look at the exmple, but in my case its not working.

Answers

  • kthorngrenkthorngren Posts: 20,142Questions: 26Answers: 4,736

    want to know if i can order other column without broke the regroup,

    Are you asking if you can order the columns within a group? If so It seems to work here:
    http://live.datatables.net/kijobine/1/edit

    Took this example and included the non-rowGroup Names column to be ordered.

    If this doesn't help then please post a link to your page or a test case (update mine) to show the issue.
    https://datatables.net/manual/tech-notes/10#How-to-provide-a-test-case

    Kevin

  • eyal_hbeyal_hb Posts: 98Questions: 31Answers: 0

    yes but also in this example when you order the name group all the regroup are Split and not stick together

  • kthorngrenkthorngren Posts: 20,142Questions: 26Answers: 4,736

    Are you saying the problem is when you click on the column to change the order? If so then use orderFixed. Here is the updated example where you can order by clicking on the columns:
    http://live.datatables.net/huhacibu/1/edit

    Kevin

  • kthorngrenkthorngren Posts: 20,142Questions: 26Answers: 4,736
  • eyal_hbeyal_hb Posts: 98Questions: 31Answers: 0

    hey Kevin i look also in this example, this good
    but in my case its not order any column on click

  • kthorngrenkthorngren Posts: 20,142Questions: 26Answers: 4,736
    edited November 2019

    That is something we would need to see to help diagnose. Can you post a link to your page or a test case replicating the issue?

    Look at the browser's console for errors.

    Is a particular column that doesn't sort?

    Does the table sort correctly without RowGroup?

    Kevin

  • eyal_hbeyal_hb Posts: 98Questions: 31Answers: 0

    hey kelvin
    the table sort correctly without and with the rowgroup
    only when i used fixedOrder the other column didnt sort
    there are no errors in console

    this is my code for the datatable

    var table = $('#Regulation').DataTable({
                dom: "frtip",
                "serverSide": true,
                "deferRender": true,
                "orderMulti": false,
                "orderCellsTop": true,
                   "ajax": {
                        "url": '@Url.Action("GetDataRegulation", "Regulation")',
                        "type": "POST",
                       "datatype": "json",
                       'data': function (data) {
                           // Read values
                           // Append to data
                           data.departmentId = departmentId;
                           data.mainSubjectId = mainSubjectId;
                           data.secondarySubjectId = secondarySubjectId;
                           data.regulationName = regulationName;
                           data.searchWords = searchWords;
                           data.tryMyLuck = tryMyLuck;
                           data.draft = draft;
                           data.deleteVal = deleteVal;
                       }
                        },
                        "language": {
                            "url": "@HttpContext.Current.Application["VirDir"]/media/language/de_HEB.json"
                        },
                        orderFixed: [[2, 'asc'], [3, 'asc']],
                        rowGroup: {
                            dataSrc: ['DepartmentName', 'MainSubject',]
                        },
                        columnDefs: [{
                            targets: [2, 3],
                            visible: false
                        }],
                        columns: [
    
                            { data: "Id", "name": "Id" },
                            { data: "Name", "name": "Name" },
                            { data: "DepartmentName", "name": "DepartmentName" },
                            { data: "MainSubject", "name": "MainSubject" },
                            { data: "SecondarySubject", "name": "SecondarySubject" },
                            {
                                "mData": "Id",
                                "orderable": false,
                                "render": function (Id, data, type, row) {
                                    return "<button class='btn btn-outline btn-primary btn-danger btn-sm' onclick='ShowRegulation(" + Id + ");' style='border-radius: 40%;display: block;'><i class='fas fa-eye' style='margin: 2px 0px 0px 0px;font-size:19px'></i></button>"
    
                                }
    
                            },
                            {
                                "mData": "Id",
                                "orderable": false,
                                "render": function (Id, data, type, row) {
                                    return "<button class='btn btn-outline btn-primary btn-Inverse btn-sm' onclick='PrintRegulation(" + Id + ");' style='border-radius: 40%;display: block;'><i class='fas fa-print' style='margin: 2px 0px 0px 0px;font-size:19px'></i></button>"
    
                                }
    
                            },
                            {
                                "mData": "Id",
                                "orderable": false,
                                "render": function (Id, data, type, row) {
                                    return "<button class='btn btn-outline btn-primary btn-Inverse btn-sm' onclick='emailSend(" + Id + ");' style='border-radius: 40%;display: block;'><i class='fas fa-envelope' style='margin: 2px 0px 0px 0px;font-size:19px'></i></button>"
    
                                }
    
                            },
                            {
                                "mData": "Id",
                                "orderable": false,
                                "render": function (Id, data, type, row) {
                                    return "<button class='btn btn-outline btn-primary btn-success btn-sm' onclick='EditRegulation(" + Id + ");' style='border-radius: 40%;display: block;'><i class='fas fa-pen' style='margin: 2px 0px 0px 0px;font-size:19px'></i></button>"
    
                                }
    
                            },
                            {
                                "data": "IsDeleted",
                                "name": "IsDeleted",
                                "orderable": false,
                                "render": function (data, type, row) {
                                    if (data == false) {
                                        return "<button class='btn btn-outline btn-primary btn-danger btn-sm' onclick='DeleteRegulation(" + row.Id + ");' style='border-radius: 40%;display: block;'><i class='fas fa-trash-alt' style='margin: 2px 0px 0px 0px;font-size:19px'></i></button>"
    
                                    }
                                    else {
                                        return "<button class='btn btn-outline btn-primary btn-Warning btn-sm' onclick='RecoverRegulation(" + row.Id + ");' style='border-radius: 40%;display: block;'><i class='fas fa-redo' style='margin: 2px 0px 0px 0px;font-size:19px'></i></button>"
    
                                    }
                                }
    
                            },
                         ],
             });
    
    
  • kthorngrenkthorngren Posts: 20,142Questions: 26Answers: 4,736

    I see you are using server side processing. In this case the server script is responsible for sorting the table. You server script will need to take into consideration the row groups and sort the other columns accordingly and return the rows for the page displayed.

    Kevin

  • eyal_hbeyal_hb Posts: 98Questions: 31Answers: 0

    ok kevin , do you have exmple?
    this is the sorting code on serverside

    //Sorting
                if (!(string.IsNullOrEmpty(sortColumn) && string.IsNullOrEmpty(sortColumnDir)))
                {
    
                    resultData = resultData.OrderBy(sortColumn + " " + sortColumnDir);
                }
    
  • colincolin Posts: 15,112Questions: 1Answers: 2,583

    You would need that fixedOrder logic to also be in the server-side sorting algorithm. I don't have an example though, I'm afraid.

  • eyal_hbeyal_hb Posts: 98Questions: 31Answers: 0

    i try many options but no one has work, i cant find a way to make it work

  • allanallan Posts: 61,446Questions: 1Answers: 10,054 Site admin

    Fixed order is prefixed onto the order that is sent to the server automatically, so there shouldn't be any special handling required on the server-side, as long as it is capable of doing multi-column sorting. Is it?

    Also keep in mind that with row grouping enabled it will sort by the grouped column(s) first - then apply the user sort inside that (assuming you use fixedOrder as Colin and Kevin have suggested).

    To see that in action take this example - click on the "Position" column - you will see that it sorted inside the groups based on the position value, but the grouping (office) still takes sorting priority.

    Regards,
    Allan

  • eyal_hbeyal_hb Posts: 98Questions: 31Answers: 0
    edited November 2019

    i dont think so, what happen now is the i get the column and the order of column(asc,desc)

                var sortColumn = Request.Form.GetValues("columns[" +
                    Request.Form.GetValues("order[0][column]").FirstOrDefault() + "][name]").FirstOrDefault();
                var sortColumnDir = Request.Form.GetValues("order[0][dir]").FirstOrDefault();
    

    and then make this before return the json

    //Sorting
                if (!(string.IsNullOrEmpty(sortColumn) && string.IsNullOrEmpty(sortColumnDir)))
                {
     
                    resultData = resultData.OrderBy(sortColumn + " " + sortColumnDir);
                }
    
This discussion has been closed.