$('#tt').treegrid({
    url: g.ctx + 'pc/sys/org/treegrid',
    method: "GET",
    singleSelect: true,
    idField: 'id',  //关键字段来标识树节点，不能重复
    treeField: 'name',  //树节点字段，也就是树节点的名称
    fitColumns: true,
    rownumbers: true,//显示一个行号列
    collapsible: true,//收起表格的内容
    width: 700,
    height: 900,
    queryParams: {parentId: -1},
    loadMsg: '数据加载中...',
    animate: true,//在节点展开或折叠的时候是否显示动画效果
    onLoadSuccess: function (data) {
        delete $(this).treegrid('options').queryParams['id'];
    },
    onContextMenu: function (e, row) {
        e.preventDefault();                    //屏蔽浏览器的菜单
        $(this).treegrid('unselectAll');    //清除所有选中项
    },
    onContextMenu: function (e, row) {
        e.preventDefault();                    //屏蔽浏览器的菜单
        $(this).treegrid('unselectAll');    //清除所有选中项
        if ($("#menu > div").size() > 1) {
            $('#menu').menu('show', {
                left: e.pageX - 10,
                top: e.pageY - 5
            });
        }
    },
    onBeforeExpand: function (row) {
        //动态设置展开查询的url
        var self = $(this);
        var url = '/organization/treegrid2?parentId=' + row.id;
        var opts = self.treegrid('options');//获取属性表格的属性对象
        if (row.state == "closed" && row.children == undefined) {
            $.post(url, function (data) {
                self.datagrid("loading", "玩命加载。。。");
                if (data) {
                    self.treegrid('append', {
                        parent: row[opts.idField],//父节点id
                        data: data.rows
                    });
                } else {
                    layer.alert("error", {icon: 5, time: 1000});
                }
                self.datagrid("loaded");
            }, "JSON");
        }
    },
    columns: [[
        {
            title: 'id',
            field: 'id',
            checkbox: true,
            align: 'center',
            width: 60
        },
        {field: 'name', title: '组织名称', width: 100, align: 'left'},
        {field: 'code', title: '组织编码', width: 100, align: 'left', hidden: 'true'},
    ]]

})

function confirm(call) {
    var cbox = $('#tt').datagrid('getSelected');
    if (!cbox) {
        layer.msg("请选中一条");
        return;
    }
    call(cbox)

}