2

I have a problem with collapsing data, but expand work properly. Console was clear and icon arrow(that shows open or closed) is working(change properly too). In what cause may be a problem?

What I do: In first loading I load the root data and all that refer to him. And after clicking I load all that refer to clicked element.

$(document).ready(function () {
    $('#tree').jqGrid({
        'url': '/user/tree',
        'colNames': ['id', 'ФИО', "Телефон", "E-mail", "Профиль"],
        'colModel': [
            {name: 'id', index: 'id', key: true, hidden: true},
            {name: 'name', index: 'name', width: 280},
            {name: 'phone', index: 'phone', width: 130, align: 'right'},
            {name: 'email', index: 'email', width: 220, align: 'right'},
            {name: 'link', index: 'link', align: 'center'}
        ],
        treeGrid: true,
        treeGridModel: 'adjacency',
        ExpandColumn: 'name',
        datatype: "json",
        height: 'auto',
        pager: "#pager"
    })
});

data I got:

{
   "rows":[
      {
         "id":10,
         "cell":{
            "name":"ajlshdjk hdjksdhakjdh",
            "phone":"878971",
            "email":"test@gmail.com7",
            "parent":9,
            "link":"test",
            "level":3,
            "isLeaf":false,
            "expanded":false,
            "id":10
         }
      },
      {
         "id":11,
         "cell":{
            "name":"akjhsdkjgh kdgadkhsgdhkqh",
            "phone":"98712873891",
            "email":"test@gmail.com8",
            "parent":9,
            "link":"test",
            "level":3,
            "isLeaf":false,
            "expanded":false,
            "id":11
         }
      }
   ],
   "records":2,
   "total":1,
   "page":1
}

And server side looks like that:

$level = ++$data['level'];
$nodeid = $data['nodeid'];
$user = User::find($nodeid);

$refs = HelperService::getNextLevelMyRefs($user);

$rows = array();
foreach ($refs as $item) {
    $obj = new \stdClass();
    $obj->id = $item->id;
    $obj->cell = array(
        'name' => $item->firstname . ' ' . $item->lastname,
        'phone' => $item->phone,
        'email' => $item->email,
        'parent' => $item->referer_id,
        'link' => 'test',
        'level' => $level,
        'isLeaf' => $this->checkForRefs($item), //need check
        'expanded' => false,
        'id' => $item->id
    );
    array_push($rows, $obj);
}

Here is a root response from server:

{
  "rows": [
    {
      "id": 7,
      "cell": {
        "name": "sjldhflj sdjfhsjh",
        "phone": "1283918",
        "email": "test@gmail.com4",
        "parent": null,
        "link": "test",
        "level": 0,
        "isLeaf": false,
        "expanded": true,
        "id": 7
      }
    },
    {
      "id": 8,
      "cell": {
        "name": "jsdhfjlash jlhsxjdhjk",
        "phone": "878",
        "email": "test@gmail.com5",
        "parent": 7,
        "link": "test",
        "level": 1,
        "isLeaf": false,
        "expanded": false,
        "id": 8
      }
    }
  ],
  "records": 2,
  "total": 1,
  "page": 1
}

Sorry for incompetence in this question, it my first experience with this library.

Oleg
  • 220,925
  • 34
  • 403
  • 798
Pls Go On
  • 51
  • 1
  • 3
  • Non-root data contains `"parent":9` as the parent, but the root elements contains only the items with `id: 7` and `id: 8` - no item with `id: 8`. If I correctly understand you then you get the first JSON response on expanding the node with `id: 7`. Why the response have `"parent":9`? Moreover it's important to know which version of jqGrid you use and from which fork ([free jqGrid](https://github.com/free-jqgrid/jqGrid), [Guriddo jqGrid JS](http://guriddo.net/?page_id=103334) or an old jqGrid in version 4.7). In any way, I would recommend you to **remove** unneeded `id` column from `colModel`. – Oleg Feb 29 '16 at 16:32
  • Sorry, it was my mistake, I just missed one response to post here. But otherwise, it's not a problem. I use it's: [link](https://github.com/tonytomov/jqGrid) – Pls Go On Feb 29 '16 at 16:51
  • Do you tried **to remove** `{name: 'id', index: 'id', key: true, hidden: true}`? I think the it could be origin of your problem. Id will be set under the name `_id_` automatically. It seems that there are a bug if you use additional `id` column with `key: true` property. By the way the code of [the old repository](https://github.com/tonytomov/jqGrid) is opened, but the product have the name Guriddo jqGrid JS now and it's not more free (see [the prices](http://guriddo.net/?page_id=103334)). It was the reason why I started to develop free jqGrid fork. – Oleg Feb 29 '16 at 16:57
  • See https://jsfiddle.net/OlegKi/b8bxb1kt/1/ the demo without `id` column – Oleg Feb 29 '16 at 16:58
  • Thank a lot for the answer! I already solved this problem. As said developer of this library it was a bug and he just updated the repository. – Pls Go On Feb 29 '16 at 17:10
  • You are welcome! You are free to use any fork of jqGrid. I develop *alternative fork* free jqGrid and how you can see on the demo https://jsfiddle.net/OlegKi/b8bxb1kt/2/ it don't have the bug, which are fixed now in Guriddo. Nevertheless I found another [small bug](https://github.com/free-jqgrid/jqGrid/commit/1543772e75a11dfa4b953731d382b77c4c5b2875) in the method `getFullTreeNode` (which is not yet fixed in Guriddo, see [the line](https://github.com/tonytomov/jqGrid/blob/v5.0.2/js/grid.treegrid.js#L395)). You can report the bug it you want to Tony (the developer). – Oleg Feb 29 '16 at 17:38

0 Answers0