rails_jq_grid 0.0.3.pre2 → 0.0.3

Sign up to get free protection for your applications and to get access to all the features.
Files changed (95) hide show
  1. data/VERSION +1 -1
  2. data/public/javascripts/rails-jqgrid/Changes.txt +0 -0
  3. data/public/javascripts/rails-jqgrid/i18n/grid.locale-bg.js +132 -1
  4. data/public/javascripts/rails-jqgrid/i18n/grid.locale-bg1251.js +132 -1
  5. data/public/javascripts/rails-jqgrid/i18n/grid.locale-cat.js +128 -1
  6. data/public/javascripts/rails-jqgrid/i18n/grid.locale-cn.js +132 -1
  7. data/public/javascripts/rails-jqgrid/i18n/grid.locale-cs.js +128 -1
  8. data/public/javascripts/rails-jqgrid/i18n/grid.locale-da.js +128 -0
  9. data/public/javascripts/rails-jqgrid/i18n/grid.locale-de.js +133 -1
  10. data/public/javascripts/rails-jqgrid/i18n/grid.locale-el.js +126 -1
  11. data/public/javascripts/rails-jqgrid/i18n/grid.locale-en.js +128 -1
  12. data/public/javascripts/rails-jqgrid/i18n/grid.locale-es.js +128 -1
  13. data/public/javascripts/rails-jqgrid/i18n/grid.locale-fa.js +145 -1
  14. data/public/javascripts/rails-jqgrid/i18n/grid.locale-fi.js +130 -1
  15. data/public/javascripts/rails-jqgrid/i18n/grid.locale-fr.js +126 -1
  16. data/public/javascripts/rails-jqgrid/i18n/grid.locale-gl.js +126 -0
  17. data/public/javascripts/rails-jqgrid/i18n/grid.locale-he.js +127 -1
  18. data/public/javascripts/rails-jqgrid/i18n/grid.locale-hu.js +129 -1
  19. data/public/javascripts/rails-jqgrid/i18n/grid.locale-is.js +126 -1
  20. data/public/javascripts/rails-jqgrid/i18n/grid.locale-it.js +1 -1
  21. data/public/javascripts/rails-jqgrid/i18n/grid.locale-ja.js +155 -1
  22. data/public/javascripts/rails-jqgrid/i18n/grid.locale-nl.js +149 -1
  23. data/public/javascripts/rails-jqgrid/i18n/grid.locale-no.js +1 -1
  24. data/public/javascripts/rails-jqgrid/i18n/grid.locale-pl.js +127 -1
  25. data/public/javascripts/rails-jqgrid/i18n/grid.locale-pt-br.js +127 -1
  26. data/public/javascripts/rails-jqgrid/i18n/grid.locale-pt.js +125 -1
  27. data/public/javascripts/rails-jqgrid/i18n/grid.locale-ro.js +139 -1
  28. data/public/javascripts/rails-jqgrid/i18n/grid.locale-ru.js +127 -1
  29. data/public/javascripts/rails-jqgrid/i18n/grid.locale-sk.js +127 -1
  30. data/public/javascripts/rails-jqgrid/i18n/grid.locale-sr.js +128 -0
  31. data/public/javascripts/rails-jqgrid/i18n/grid.locale-sv.js +127 -1
  32. data/public/javascripts/rails-jqgrid/i18n/grid.locale-tr.js +126 -1
  33. data/public/javascripts/rails-jqgrid/i18n/grid.locale-ua.js +127 -1
  34. data/public/javascripts/rails-jqgrid/install.txt +0 -0
  35. data/public/javascripts/rails-jqgrid/jquery.jqGrid.min.js +445 -432
  36. data/public/javascripts/rails-jqgrid/src/JsonXml.js +329 -329
  37. data/public/javascripts/rails-jqgrid/src/css/ellipsis-xbl.xml +0 -0
  38. data/public/javascripts/rails-jqgrid/src/css/ui.jqgrid.css +139 -129
  39. data/public/javascripts/rails-jqgrid/src/css/ui.multiselect.css +0 -0
  40. data/public/javascripts/rails-jqgrid/src/grid.base.js +3078 -3003
  41. data/public/javascripts/rails-jqgrid/src/grid.celledit.js +486 -486
  42. data/public/javascripts/rails-jqgrid/src/grid.common.js +646 -636
  43. data/public/javascripts/rails-jqgrid/src/grid.custom.js +820 -817
  44. data/public/javascripts/rails-jqgrid/src/grid.formedit.js +1954 -1872
  45. data/public/javascripts/rails-jqgrid/src/grid.grouping.js +250 -0
  46. data/public/javascripts/rails-jqgrid/src/grid.import.js +200 -200
  47. data/public/javascripts/rails-jqgrid/src/grid.inlinedit.js +255 -250
  48. data/public/javascripts/rails-jqgrid/src/grid.jqueryui.js +504 -503
  49. data/public/javascripts/rails-jqgrid/src/grid.loader.js +1 -0
  50. data/public/javascripts/rails-jqgrid/src/grid.postext.js +63 -63
  51. data/public/javascripts/rails-jqgrid/src/grid.setcolumns.js +125 -125
  52. data/public/javascripts/rails-jqgrid/src/grid.subgrid.js +260 -260
  53. data/public/javascripts/rails-jqgrid/src/grid.tbltogrid.js +106 -106
  54. data/public/javascripts/rails-jqgrid/src/grid.treegrid.js +489 -482
  55. data/public/javascripts/rails-jqgrid/src/i18n/grid.locale-bg.js +132 -132
  56. data/public/javascripts/rails-jqgrid/src/i18n/grid.locale-bg1251.js +132 -132
  57. data/public/javascripts/rails-jqgrid/src/i18n/grid.locale-cat.js +128 -128
  58. data/public/javascripts/rails-jqgrid/src/i18n/grid.locale-cn.js +132 -132
  59. data/public/javascripts/rails-jqgrid/src/i18n/grid.locale-cs.js +128 -128
  60. data/public/javascripts/rails-jqgrid/src/i18n/grid.locale-da.js +128 -0
  61. data/public/javascripts/rails-jqgrid/src/i18n/grid.locale-de.js +132 -127
  62. data/public/javascripts/rails-jqgrid/src/i18n/grid.locale-dk.js +0 -0
  63. data/public/javascripts/rails-jqgrid/src/i18n/grid.locale-el.js +126 -126
  64. data/public/javascripts/rails-jqgrid/src/i18n/grid.locale-en.js +128 -128
  65. data/public/javascripts/rails-jqgrid/src/i18n/grid.locale-es.js +128 -128
  66. data/public/javascripts/rails-jqgrid/src/i18n/grid.locale-fa.js +145 -125
  67. data/public/javascripts/rails-jqgrid/src/i18n/grid.locale-fi.js +130 -130
  68. data/public/javascripts/rails-jqgrid/src/i18n/grid.locale-fr.js +2 -2
  69. data/public/javascripts/rails-jqgrid/src/i18n/grid.locale-gl.js +126 -0
  70. data/public/javascripts/rails-jqgrid/src/i18n/grid.locale-he.js +127 -127
  71. data/public/javascripts/rails-jqgrid/src/i18n/grid.locale-hu.js +129 -129
  72. data/public/javascripts/rails-jqgrid/src/i18n/grid.locale-is.js +126 -126
  73. data/public/javascripts/rails-jqgrid/src/i18n/grid.locale-it.js +0 -0
  74. data/public/javascripts/rails-jqgrid/src/i18n/grid.locale-ja.js +155 -155
  75. data/public/javascripts/rails-jqgrid/src/i18n/grid.locale-nl.js +148 -148
  76. data/public/javascripts/rails-jqgrid/src/i18n/grid.locale-no.js +0 -0
  77. data/public/javascripts/rails-jqgrid/src/i18n/grid.locale-pl.js +126 -126
  78. data/public/javascripts/rails-jqgrid/src/i18n/grid.locale-pt-br.js +127 -127
  79. data/public/javascripts/rails-jqgrid/src/i18n/grid.locale-pt.js +125 -125
  80. data/public/javascripts/rails-jqgrid/src/i18n/grid.locale-ro.js +139 -139
  81. data/public/javascripts/rails-jqgrid/src/i18n/grid.locale-ru.js +127 -127
  82. data/public/javascripts/rails-jqgrid/src/i18n/grid.locale-sk.js +127 -127
  83. data/public/javascripts/rails-jqgrid/src/i18n/grid.locale-sr.js +128 -0
  84. data/public/javascripts/rails-jqgrid/src/i18n/grid.locale-sv.js +127 -127
  85. data/public/javascripts/rails-jqgrid/src/i18n/grid.locale-tr.js +126 -126
  86. data/public/javascripts/rails-jqgrid/src/i18n/grid.locale-ua.js +127 -127
  87. data/public/javascripts/rails-jqgrid/src/jqDnR.js +68 -67
  88. data/public/javascripts/rails-jqgrid/src/jqModal.js +68 -68
  89. data/public/javascripts/rails-jqgrid/src/jquery.fmatter.js +563 -541
  90. data/public/javascripts/rails-jqgrid/src/jquery.searchFilter.js +1 -1
  91. data/public/javascripts/rails-jqgrid/src/ui.multiselect.js +0 -0
  92. data/public/stylesheets/rails-jqgrid/ellipsis-xbl.xml +0 -0
  93. data/public/stylesheets/rails-jqgrid/ui.jqgrid.css +139 -2
  94. data/rails_jq_grid.gemspec +10 -3
  95. metadata +15 -11
@@ -1,106 +1,106 @@
1
- /*
2
- Transform a table to a jqGrid.
3
- Peter Romianowski <peter.romianowski@optivo.de>
4
- If the first column of the table contains checkboxes or
5
- radiobuttons then the jqGrid is made selectable.
6
- */
7
- // Addition - selector can be a class or id
8
- function tableToGrid(selector, options) {
9
- jQuery(selector).each(function() {
10
- if(this.grid) {return;} //Adedd from Tony Tomov
11
- // This is a small "hack" to make the width of the jqGrid 100%
12
- jQuery(this).width("99%");
13
- var w = jQuery(this).width();
14
-
15
- // Text whether we have single or multi select
16
- var inputCheckbox = jQuery('input[type=checkbox]:first', jQuery(this));
17
- var inputRadio = jQuery('input[type=radio]:first', jQuery(this));
18
- var selectMultiple = inputCheckbox.length > 0;
19
- var selectSingle = !selectMultiple && inputRadio.length > 0;
20
- var selectable = selectMultiple || selectSingle;
21
- var inputName = inputCheckbox.attr("name") || inputRadio.attr("name");
22
-
23
- // Build up the columnModel and the data
24
- var colModel = [];
25
- var colNames = [];
26
- jQuery('th', jQuery(this)).each(function() {
27
- if (colModel.length === 0 && selectable) {
28
- colModel.push({
29
- name: '__selection__',
30
- index: '__selection__',
31
- width: 0,
32
- hidden: true
33
- });
34
- colNames.push('__selection__');
35
- } else {
36
- colModel.push({
37
- name: jQuery(this).attr("id") || jQuery.trim(jQuery.jgrid.stripHtml(jQuery(this).html())).split(' ').join('_'),
38
- index: jQuery(this).attr("id") || jQuery.trim(jQuery.jgrid.stripHtml(jQuery(this).html())).split(' ').join('_'),
39
- width: jQuery(this).width() || 150
40
- });
41
- colNames.push(jQuery(this).html());
42
- }
43
- });
44
- var data = [];
45
- var rowIds = [];
46
- var rowChecked = [];
47
- jQuery('tbody > tr', jQuery(this)).each(function() {
48
- var row = {};
49
- var rowPos = 0;
50
- jQuery('td', jQuery(this)).each(function() {
51
- if (rowPos === 0 && selectable) {
52
- var input = jQuery('input', jQuery(this));
53
- var rowId = input.attr("value");
54
- rowIds.push(rowId || data.length);
55
- if (input.attr("checked")) {
56
- rowChecked.push(rowId);
57
- }
58
- row[colModel[rowPos].name] = input.attr("value");
59
- } else {
60
- row[colModel[rowPos].name] = jQuery(this).html();
61
- }
62
- rowPos++;
63
- });
64
- if(rowPos >0) { data.push(row); }
65
- });
66
-
67
- // Clear the original HTML table
68
- jQuery(this).empty();
69
-
70
- // Mark it as jqGrid
71
- jQuery(this).addClass("scroll");
72
-
73
- jQuery(this).jqGrid(jQuery.extend({
74
- datatype: "local",
75
- width: w,
76
- colNames: colNames,
77
- colModel: colModel,
78
- multiselect: selectMultiple
79
- //inputName: inputName,
80
- //inputValueCol: imputName != null ? "__selection__" : null
81
- }, options || {}));
82
-
83
- // Add data
84
- var a;
85
- for (a = 0; a < data.length; a++) {
86
- var id = null;
87
- if (rowIds.length > 0) {
88
- id = rowIds[a];
89
- if (id && id.replace) {
90
- // We have to do this since the value of a checkbox
91
- // or radio button can be anything
92
- id = encodeURIComponent(id).replace(/[.\-%]/g, "_");
93
- }
94
- }
95
- if (id === null) {
96
- id = a + 1;
97
- }
98
- jQuery(this).jqGrid("addRowData",id, data[a]);
99
- }
100
-
101
- // Set the selection
102
- for (a = 0; a < rowChecked.length; a++) {
103
- jQuery(this).jqGrid("setSelection",rowChecked[a]);
104
- }
105
- });
106
- };
1
+ /*
2
+ Transform a table to a jqGrid.
3
+ Peter Romianowski <peter.romianowski@optivo.de>
4
+ If the first column of the table contains checkboxes or
5
+ radiobuttons then the jqGrid is made selectable.
6
+ */
7
+ // Addition - selector can be a class or id
8
+ function tableToGrid(selector, options) {
9
+ jQuery(selector).each(function() {
10
+ if(this.grid) {return;} //Adedd from Tony Tomov
11
+ // This is a small "hack" to make the width of the jqGrid 100%
12
+ jQuery(this).width("99%");
13
+ var w = jQuery(this).width();
14
+
15
+ // Text whether we have single or multi select
16
+ var inputCheckbox = jQuery('input[type=checkbox]:first', jQuery(this));
17
+ var inputRadio = jQuery('input[type=radio]:first', jQuery(this));
18
+ var selectMultiple = inputCheckbox.length > 0;
19
+ var selectSingle = !selectMultiple && inputRadio.length > 0;
20
+ var selectable = selectMultiple || selectSingle;
21
+ //var inputName = inputCheckbox.attr("name") || inputRadio.attr("name");
22
+
23
+ // Build up the columnModel and the data
24
+ var colModel = [];
25
+ var colNames = [];
26
+ jQuery('th', jQuery(this)).each(function() {
27
+ if (colModel.length === 0 && selectable) {
28
+ colModel.push({
29
+ name: '__selection__',
30
+ index: '__selection__',
31
+ width: 0,
32
+ hidden: true
33
+ });
34
+ colNames.push('__selection__');
35
+ } else {
36
+ colModel.push({
37
+ name: jQuery(this).attr("id") || jQuery.trim(jQuery.jgrid.stripHtml(jQuery(this).html())).split(' ').join('_'),
38
+ index: jQuery(this).attr("id") || jQuery.trim(jQuery.jgrid.stripHtml(jQuery(this).html())).split(' ').join('_'),
39
+ width: jQuery(this).width() || 150
40
+ });
41
+ colNames.push(jQuery(this).html());
42
+ }
43
+ });
44
+ var data = [];
45
+ var rowIds = [];
46
+ var rowChecked = [];
47
+ jQuery('tbody > tr', jQuery(this)).each(function() {
48
+ var row = {};
49
+ var rowPos = 0;
50
+ jQuery('td', jQuery(this)).each(function() {
51
+ if (rowPos === 0 && selectable) {
52
+ var input = jQuery('input', jQuery(this));
53
+ var rowId = input.attr("value");
54
+ rowIds.push(rowId || data.length);
55
+ if (input.attr("checked")) {
56
+ rowChecked.push(rowId);
57
+ }
58
+ row[colModel[rowPos].name] = input.attr("value");
59
+ } else {
60
+ row[colModel[rowPos].name] = jQuery(this).html();
61
+ }
62
+ rowPos++;
63
+ });
64
+ if(rowPos >0) { data.push(row); }
65
+ });
66
+
67
+ // Clear the original HTML table
68
+ jQuery(this).empty();
69
+
70
+ // Mark it as jqGrid
71
+ jQuery(this).addClass("scroll");
72
+
73
+ jQuery(this).jqGrid(jQuery.extend({
74
+ datatype: "local",
75
+ width: w,
76
+ colNames: colNames,
77
+ colModel: colModel,
78
+ multiselect: selectMultiple
79
+ //inputName: inputName,
80
+ //inputValueCol: imputName != null ? "__selection__" : null
81
+ }, options || {}));
82
+
83
+ // Add data
84
+ var a;
85
+ for (a = 0; a < data.length; a++) {
86
+ var id = null;
87
+ if (rowIds.length > 0) {
88
+ id = rowIds[a];
89
+ if (id && id.replace) {
90
+ // We have to do this since the value of a checkbox
91
+ // or radio button can be anything
92
+ id = encodeURIComponent(id).replace(/[.\-%]/g, "_");
93
+ }
94
+ }
95
+ if (id === null) {
96
+ id = a + 1;
97
+ }
98
+ jQuery(this).jqGrid("addRowData",id, data[a]);
99
+ }
100
+
101
+ // Set the selection
102
+ for (a = 0; a < rowChecked.length; a++) {
103
+ jQuery(this).jqGrid("setSelection",rowChecked[a]);
104
+ }
105
+ });
106
+ };
@@ -1,483 +1,490 @@
1
- ;(function($) {
2
- /*
3
- **
4
- * jqGrid extension - Tree Grid
5
- * Tony Tomov tony@trirand.com
6
- * http://trirand.com/blog/
7
- * Dual licensed under the MIT and GPL licenses:
8
- * http://www.opensource.org/licenses/mit-license.php
9
- * http://www.gnu.org/licenses/gpl.html
10
- **/
11
- $.jgrid.extend({
12
- setTreeNode : function(rd, row){
13
- return this.each(function(){
14
- var $t = this;
15
- if( !$t.grid || !$t.p.treeGrid ) { return; }
16
- var expCol = $t.p.expColInd;
17
- var expanded = $t.p.treeReader.expanded_field;
18
- var isLeaf = $t.p.treeReader.leaf_field;
19
- var level = $t.p.treeReader.level_field;
20
- row.level = rd[level];
21
-
22
- if($t.p.treeGridModel == 'nested') {
23
- var lft = rd[$t.p.treeReader.left_field],
24
- rgt = rd[$t.p.treeReader.right_field];
25
- if(!rd[isLeaf]) {
26
- // NS Model
27
- rd[isLeaf] = (parseInt(rgt,10) === parseInt(lft,10)+1) ? 'true' : 'false';
28
- }
29
- } else {
30
- //row.parent_id = rd[$t.p.treeReader.parent_id_field];
31
- }
32
- var curLevel = parseInt(rd[level],10), ident,lftpos;
33
- if($t.p.tree_root_level === 0) {
34
- ident = curLevel+1;
35
- lftpos = curLevel;
36
- } else {
37
- ident = curLevel;
38
- lftpos = curLevel -1;
39
- }
40
- var twrap = "<div class='tree-wrap tree-wrap-"+$t.p.direction+"' style='width:"+(ident*18)+"px;'>";
41
- twrap += "<div style='"+($t.p.direction=="rtl" ? "right:" : "left:")+(lftpos*18)+"px;' class='ui-icon ";
42
-
43
- if(rd[isLeaf] == "true" || rd[isLeaf] === true) {
44
- twrap += $t.p.treeIcons.leaf+" tree-leaf'";
45
- rd[isLeaf] = true;
46
- rd[expanded] = false;
47
- } else {
48
- if(rd[expanded] == "true" || rd[expanded] === true) {
49
- twrap += $t.p.treeIcons.minus+" tree-minus treeclick'";
50
- rd[expanded] = true;
51
- } else {
52
- twrap += $t.p.treeIcons.plus+" tree-plus treeclick'";
53
- rd[expanded] = false;
54
- }
55
- rd[isLeaf] = false;
56
- }
57
- twrap += "</div></div>";
58
- if(!$t.p.loadonce) {
59
- rd[$t.p.localReader.id] = row.id;
60
- $t.p.data.push(rd);
61
- $t.p._index[row.id]=$t.p.data.length-1;
62
- }
63
- if(parseInt(rd[level],10) !== parseInt($t.p.tree_root_level,10)) {
64
- if(!$($t).jqGrid("isVisibleNode",rd)){
65
- $(row).css("display","none");
66
- }
67
- }
68
-
69
- $("td:eq("+expCol+")",row).wrapInner("<span></span>").prepend(twrap);
70
- $(".treeclick",row).bind("click",function(e){
71
- var target = e.target || e.srcElement,
72
- ind2 =$(target,$t.rows).closest("tr.jqgrow")[0].id,
73
- pos = $t.p._index[ind2],
74
- isLeaf = $t.p.treeReader.leaf_field,
75
- expanded = $t.p.treeReader.expanded_field;
76
- if(!$t.p.data[pos][isLeaf]){
77
- if($t.p.data[pos][expanded]){
78
- $($t).jqGrid("collapseRow",$t.p.data[pos]);
79
- $($t).jqGrid("collapseNode",$t.p.data[pos]);
80
- } else {
81
- $($t).jqGrid("expandRow",$t.p.data[pos]);
82
- $($t).jqGrid("expandNode",$t.p.data[pos]);
83
- }
84
- }
85
- return false;
86
- });
87
- if($t.p.ExpandColClick === true) {
88
- $("span", row).css("cursor","pointer").bind("click",function(e){
89
- var target = e.target || e.srcElement,
90
- ind2 =$(target,$t.rows).closest("tr.jqgrow")[0].id,
91
- pos = $t.p._index[ind2],
92
- isLeaf = $t.p.treeReader.leaf_field,
93
- expanded = $t.p.treeReader.expanded_field;
94
- if(!$t.p.data[pos][isLeaf]){
95
- if($t.p.data[pos][expanded]){
96
- $($t).jqGrid("collapseRow",$t.p.data[pos]);
97
- $($t).jqGrid("collapseNode",$t.p.data[pos]);
98
- } else {
99
- $($t).jqGrid("expandRow",$t.p.data[pos]);
100
- $($t).jqGrid("expandNode",$t.p.data[pos]);
101
- }
102
- }
103
- $($t).jqGrid("setSelection",ind2);
104
- return false;
105
- });
106
- }
107
- });
108
- },
109
- setTreeGrid : function() {
110
- return this.each(function (){
111
- var $t = this, i=0, pico;
112
- if(!$t.p.treeGrid) { return; }
113
- if(!$t.p.treedatatype ) { $.extend($t.p,{treedatatype: $t.p.datatype}); }
114
- $t.p.subGrid = false; $t.p.altRows =false;
115
- $t.p.pgbuttons = false; $t.p.pginput = false;
116
- $t.p.multiselect = false; $t.p.rowList = [];
117
- pico = 'ui-icon-triangle-1-' + ($t.p.direction=="rtl" ? 'w' : 'e');
118
- $t.p.treeIcons = $.extend({plus:pico,minus:'ui-icon-triangle-1-s',leaf:'ui-icon-radio-off'},$t.p.treeIcons || {});
119
- if($t.p.treeGridModel == 'nested') {
120
- $t.p.treeReader = $.extend({
121
- level_field: "level",
122
- left_field:"lft",
123
- right_field: "rgt",
124
- leaf_field: "isLeaf",
125
- expanded_field: "expanded"
126
- },$t.p.treeReader);
127
- } else
128
- if($t.p.treeGridModel == 'adjacency') {
129
- $t.p.treeReader = $.extend({
130
- level_field: "level",
131
- parent_id_field: "parent",
132
- leaf_field: "isLeaf",
133
- expanded_field: "expanded"
134
- },$t.p.treeReader );
135
- }
136
- for (var key in $t.p.colModel){
137
- if($t.p.colModel.hasOwnProperty(key)) {
138
- if($t.p.colModel[key].name == $t.p.ExpandColumn) {
139
- $t.p.expColInd = i;
140
- break;
141
- }
142
- i++;
143
- }
144
- }
145
- if(!$t.p.expColInd) { $t.p.expColInd = 0; }
146
- $.each($t.p.treeReader,function(i,n){
147
- if(n){
148
- $t.p.colNames.push(n);
149
- $t.p.colModel.push({name:n,width:1,hidden:true,sortable:false,resizable:false,hidedlg:true,editable:true,search:false});
150
- }
151
- });
152
- });
153
- },
154
- expandRow: function (record){
155
- this.each(function(){
156
- var $t = this;
157
- if(!$t.grid || !$t.p.treeGrid) { return; }
158
- var childern = $($t).jqGrid("getNodeChildren",record),
159
- //if ($($t).jqGrid("isVisibleNode",record)) {
160
- expanded = $t.p.treeReader.expanded_field;
161
- $(childern).each(function(i){
162
- var id = $.jgrid.getAccessor(this,$t.p.localReader.id);
163
- $("#"+id,$t.grid.bDiv).css("display","");
164
- if(this[expanded]) {
165
- $($t).jqGrid("expandRow",this);
166
- }
167
- });
168
- //}
169
- });
170
- },
171
- collapseRow : function (record) {
172
- this.each(function(){
173
- var $t = this;
174
- if(!$t.grid || !$t.p.treeGrid) { return; }
175
- var childern = $($t).jqGrid("getNodeChildren",record),
176
- expanded = $t.p.treeReader.expanded_field;
177
- $(childern).each(function(i){
178
- var id = $.jgrid.getAccessor(this,$t.p.localReader.id)
179
- $("#"+id,$t.grid.bDiv).css("display","none");
180
- if(this[expanded]){
181
- $($t).jqGrid("collapseRow",this);
182
- }
183
- });
184
- });
185
- },
186
- // NS ,adjacency models
187
- getRootNodes : function() {
188
- var result = [];
189
- this.each(function(){
190
- var $t = this;
191
- if(!$t.grid || !$t.p.treeGrid) { return; }
192
- switch ($t.p.treeGridModel) {
193
- case 'nested' :
194
- var level = $t.p.treeReader.level_field;
195
- $($t.p.data).each(function(i){
196
- if(parseInt(this[level],10) === parseInt($t.p.tree_root_level,10)) {
197
- result.push(this);
198
- }
199
- });
200
- break;
201
- case 'adjacency' :
202
- var parent_id = $t.p.treeReader.parent_id_field;
203
- $($t.p.data).each(function(i){
204
- if(this[parent_id] === null || String(this[parent_id]).toLowerCase() == "null") {
205
- result.push(this);
206
- }
207
- });
208
- break;
209
- }
210
- });
211
- return result;
212
- },
213
- getNodeDepth : function(rc) {
214
- var ret = null;
215
- this.each(function(){
216
- if(!this.grid || !this.p.treeGrid) { return; }
217
- var $t = this;
218
- switch ($t.p.treeGridModel) {
219
- case 'nested' :
220
- var level = $t.p.treeReader.level_field;
221
- ret = parseInt(rc[level],10) - parseInt($t.p.tree_root_level,10);
222
- break;
223
- case 'adjacency' :
224
- ret = $($t).jqGrid("getNodeAncestors",rc).length;
225
- break;
226
- }
227
- });
228
- return ret;
229
- },
230
- getNodeParent : function(rc) {
231
- var result = null;
232
- this.each(function(){
233
- var $t = this;
234
- if(!$t.grid || !$t.p.treeGrid) { return; }
235
- switch ($t.p.treeGridModel) {
236
- case 'nested' :
237
- var lftc = $t.p.treeReader.left_field,
238
- rgtc = $t.p.treeReader.right_field,
239
- levelc = $t.p.treeReader.level_field,
240
- lft = parseInt(rc[lftc],10), rgt = parseInt(rc[rgtc],10), level = parseInt(rc[levelc],10);
241
- $(this.p.data).each(function(){
242
- if(parseInt(this[levelc],10) === level-1 && parseInt(this[lftc],10) < lft && parseInt(this[rgtc],10) > rgt) {
243
- result = this;
244
- return false;
245
- }
246
- });
247
- break;
248
- case 'adjacency' :
249
- var parent_id = $t.p.treeReader.parent_id_field;
250
- $(this.p.data).each(function(i,val){
251
- if(this.id == rc[parent_id] ) {
252
- result = this;
253
- return false;
254
- }
255
- });
256
- break;
257
- }
258
- });
259
- return result;
260
- },
261
- getNodeChildren : function(rc) {
262
- var result = [];
263
- this.each(function(){
264
- var $t = this;
265
- if(!$t.grid || !$t.p.treeGrid) { return; }
266
- switch ($t.p.treeGridModel) {
267
- case 'nested' :
268
- var lftc = $t.p.treeReader.left_field,
269
- rgtc = $t.p.treeReader.right_field,
270
- levelc = $t.p.treeReader.level_field,
271
- lft = parseInt(rc[lftc],10), rgt = parseInt(rc[rgtc],10), level = parseInt(rc[levelc],10);
272
- $(this.p.data).each(function(i){
273
- if(parseInt(this[levelc],10) === level+1 && parseInt(this[lftc],10) > lft && parseInt(this[rgtc],10) < rgt) {
274
- result.push(this);
275
- }
276
- });
277
- break;
278
- case 'adjacency' :
279
- var parent_id = $t.p.treeReader.parent_id_field;
280
- $(this.p.data).each(function(i,val){
281
- if(this[parent_id] == rc.id) {
282
- result.push(this);
283
- }
284
- });
285
- break;
286
- }
287
- });
288
- return result;
289
- },
290
- getFullTreeNode : function(rc) {
291
- var result = [];
292
- this.each(function(){
293
- var $t = this, len;
294
- if(!$t.grid || !$t.p.treeGrid) { return; }
295
- switch ($t.p.treeGridModel) {
296
- case 'nested' :
297
- var lftc = $t.p.treeReader.left_field,
298
- rgtc = $t.p.treeReader.right_field,
299
- levelc = $t.p.treeReader.level_field,
300
- lft = parseInt(rc[lftc],10), rgt = parseInt(rc[rgtc],10), level = parseInt(rc[levelc],10);
301
- $(this.p.data).each(function(i){
302
- if(parseInt(this[levelc],10) >= level && parseInt(this[lftc],10) >= lft && parseInt(this[lftc],10) <= rgt) {
303
- result.push(this);
304
- }
305
- });
306
- break;
307
- case 'adjacency' :
308
- result.push(rc);
309
- var parent_id = $t.p.treeReader.parent_id_field;
310
- $(this.p.data).each(function(i){
311
- len = result.length;
312
- for (i = 0; i < len; i++) {
313
- if (result[i].id == this[parent_id]) {
314
- result.push(this);
315
- break;
316
- }
317
- }
318
- });
319
- break;
320
- }
321
- });
322
- return result;
323
- },
324
- // End NS, adjacency Model
325
- getNodeAncestors : function(rc) {
326
- var ancestors = [];
327
- this.each(function(){
328
- if(!this.grid || !this.p.treeGrid) { return; }
329
- var parent = $(this).jqGrid("getNodeParent",rc);
330
- while (parent) {
331
- ancestors.push(parent);
332
- parent = $(this).jqGrid("getNodeParent",parent);
333
- }
334
- });
335
- return ancestors;
336
- },
337
- isVisibleNode : function(rc) {
338
- var result = true;
339
- this.each(function(){
340
- var $t = this;
341
- if(!$t.grid || !$t.p.treeGrid) { return; }
342
- var ancestors = $($t).jqGrid("getNodeAncestors",rc),
343
- expanded = $t.p.treeReader.expanded_field;
344
- $(ancestors).each(function(){
345
- result = result && this[expanded];
346
- if(!result) {return false;}
347
- });
348
- });
349
- return result;
350
- },
351
- isNodeLoaded : function(rc) {
352
- var result;
353
- this.each(function(){
354
- var $t = this;
355
- if(!$t.grid || !$t.p.treeGrid) { return; }
356
- var isLeaf = $t.p.treeReader.leaf_field;
357
- if(rc.loaded !== undefined) {
358
- result = rc.loaded;
359
- } else if( rc[isLeaf] || $($t).jqGrid("getNodeChildren",rc).length > 0){
360
- result = true;
361
- } else {
362
- result = false;
363
- }
364
- });
365
- return result;
366
- },
367
- expandNode : function(rc) {
368
- return this.each(function(){
369
- if(!this.grid || !this.p.treeGrid) { return; }
370
- var expanded = this.p.treeReader.expanded_field;
371
- if(!rc[expanded]) {
372
- var id = $.jgrid.getAccessor(rc,this.p.localReader.id)
373
- var rc1 = $("#"+id,this.grid.bDiv)[0];
374
- var position = this.p._index[id];
375
- if( $(this).jqGrid("isNodeLoaded",this.p.data[position]) ) {
376
- rc[expanded] = true;
377
- $("div.treeclick",rc1).removeClass(this.p.treeIcons.plus+" tree-plus").addClass(this.p.treeIcons.minus+" tree-minus");
378
- } else {
379
- rc[expanded] = true;
380
- $("div.treeclick",rc1).removeClass(this.p.treeIcons.plus+" tree-plus").addClass(this.p.treeIcons.minus+" tree-minus");
381
- this.p.treeANode = rc1.rowIndex;
382
- this.p.datatype = this.p.treedatatype;
383
- if(this.p.treeGridModel == 'nested') {
384
- $(this).jqGrid("setGridParam",{postData:{nodeid:id,n_left:rc.lft,n_right:rc.rgt,n_level:rc.level}});
385
- } else {
386
- $(this).jqGrid("setGridParam",{postData:{nodeid:id,parentid:rc.parent_id,n_level:rc.level}});
387
- }
388
- $(this).trigger("reloadGrid");
389
- if(this.p.treeGridModel == 'nested') {
390
- $(this).jqGrid("setGridParam",{postData:{nodeid:'',n_left:'',n_right:'',n_level:''}});
391
- } else {
392
- $(this).jqGrid("setGridParam",{postData:{nodeid:'',parentid:'',n_level:''}});
393
- }
394
- }
395
- }
396
- });
397
- },
398
- collapseNode : function(rc) {
399
- return this.each(function(){
400
- if(!this.grid || !this.p.treeGrid) { return; }
401
- if(rc.expanded) {
402
- rc.expanded = false;
403
- var id = $.jgrid.getAccessor(rc,this.p.localReader.id)
404
- var rc1 = $("#"+id,this.grid.bDiv)[0];
405
- $("div.treeclick",rc1).removeClass(this.p.treeIcons.minus+" tree-minus").addClass(this.p.treeIcons.plus+" tree-plus");
406
- }
407
- });
408
- },
409
- SortTree : function( sortname, newDir, st, datefmt) {
410
- return this.each(function(){
411
- if(!this.grid || !this.p.treeGrid) { return; }
412
- var i, len,
413
- rec, records = [], $t = this, query, roots,
414
- rt = $(this).jqGrid("getRootNodes");
415
- // Sorting roots
416
- query = $.jgrid.from(rt);
417
- query.orderBy(sortname,newDir,st, datefmt);
418
- roots = query.select();
419
-
420
- // Sorting children
421
- for (i = 0, len = roots.length; i < len; i++) {
422
- rec = roots[i];
423
- records.push(rec);
424
- $(this).jqGrid("collectChildrenSortTree",records, rec, sortname, newDir,st, datefmt);
425
- }
426
- $.each(records, function(index, row) {
427
- var id = $.jgrid.getAccessor(this,$t.p.localReader.id);
428
- if(index===0) {
429
- var row1 = $("#"+id,$t.grid.bDiv);
430
- $("td",row1).each( function( k ) {
431
- $(this).css("width",$t.grid.headers[k].width+"px");
432
- });
433
- $t.grid.cols = row1[0].cells;
434
- }
435
- $('tbody',$t.grid.bDiv).append($("#"+id,$t.grid.bDiv));
436
- });
437
- query = null; roots=null;records=null;
438
- });
439
- },
440
- collectChildrenSortTree : function(records, rec, sortname, newDir,st, datefmt) {
441
- return this.each(function(){
442
- if(!this.grid || !this.p.treeGrid) { return; }
443
- var i, len,
444
- child, ch, query, children;
445
- ch = $(this).jqGrid("getNodeChildren",rec);
446
- query = $.jgrid.from(ch);
447
- query.orderBy(sortname,newDir,newDir,st, datefmt);
448
- children = query.select();
449
- for (i = 0, len = children.length; i < len; i++) {
450
- child = children[i];
451
- records.push(child);
452
- $(this).jqGrid("collectChildrenSortTree",records, child, sortname, newDir, st, datefmt);
453
- }
454
- });
455
- },
456
- // experimental
457
- setTreeRow : function(rowid, data) {
458
- var nm, success=false;
459
- this.each(function(){
460
- var t = this;
461
- if(!t.grid || !t.p.treeGrid) { return; }
462
- success = $(t).jqGrid("setRowData",rowid,data);
463
- });
464
- return success;
465
- },
466
- delTreeNode : function (rowid) {
467
- return this.each(function () {
468
- var $t = this;
469
- if(!$t.grid || !$t.p.treeGrid) { return; }
470
- var rc = $($t).jqGrid("getInd",rowid,true);
471
- if (rc) {
472
- var dr = $($t).jqGrid("getNodeChildren",rc);
473
- if(dr.length>0){
474
- for (var i=0;i<dr.length;i++){
475
- $($t).jqGrid("delRowData",dr[i].id);
476
- }
477
- }
478
- $($t).jqGrid("delRowData",rc.id);
479
- }
480
- });
481
- }
482
- });
1
+ ;(function($) {
2
+ /*
3
+ **
4
+ * jqGrid extension - Tree Grid
5
+ * Tony Tomov tony@trirand.com
6
+ * http://trirand.com/blog/
7
+ * Dual licensed under the MIT and GPL licenses:
8
+ * http://www.opensource.org/licenses/mit-license.php
9
+ * http://www.gnu.org/licenses/gpl.html
10
+ **/
11
+ $.jgrid.extend({
12
+ setTreeNode : function(rd, row){
13
+ return this.each(function(){
14
+ var $t = this;
15
+ if( !$t.grid || !$t.p.treeGrid ) { return; }
16
+ var expCol = $t.p.expColInd,
17
+ expanded = $t.p.treeReader.expanded_field,
18
+ isLeaf = $t.p.treeReader.leaf_field,
19
+ level = $t.p.treeReader.level_field,
20
+ loaded = $t.p.treeReader.loaded;
21
+
22
+ row.level = rd[level];
23
+
24
+ if($t.p.treeGridModel == 'nested') {
25
+ var lft = rd[$t.p.treeReader.left_field],
26
+ rgt = rd[$t.p.treeReader.right_field];
27
+ if(!rd[isLeaf]) {
28
+ // NS Model
29
+ rd[isLeaf] = (parseInt(rgt,10) === parseInt(lft,10)+1) ? 'true' : 'false';
30
+ }
31
+ } else {
32
+ //row.parent_id = rd[$t.p.treeReader.parent_id_field];
33
+ }
34
+ var curLevel = parseInt(rd[level],10), ident,lftpos;
35
+ if($t.p.tree_root_level === 0) {
36
+ ident = curLevel+1;
37
+ lftpos = curLevel;
38
+ } else {
39
+ ident = curLevel;
40
+ lftpos = curLevel -1;
41
+ }
42
+ var twrap = "<div class='tree-wrap tree-wrap-"+$t.p.direction+"' style='width:"+(ident*18)+"px;'>";
43
+ twrap += "<div style='"+($t.p.direction=="rtl" ? "right:" : "left:")+(lftpos*18)+"px;' class='ui-icon ";
44
+
45
+ if(rd[loaded] != undefined) {
46
+ if(rd[loaded]=="true" || rd[loaded]===true) {
47
+ rd[loaded] = true;
48
+ } else {
49
+ rd[loaded] = false;
50
+ }
51
+ }
52
+ if(rd[isLeaf] == "true" || rd[isLeaf] === true) {
53
+ twrap += $t.p.treeIcons.leaf+" tree-leaf'";
54
+ rd[isLeaf] = true;
55
+ rd[expanded] = false;
56
+ } else {
57
+ if(rd[expanded] == "true" || rd[expanded] === true) {
58
+ twrap += $t.p.treeIcons.minus+" tree-minus treeclick'";
59
+ rd[expanded] = true;
60
+ } else {
61
+ twrap += $t.p.treeIcons.plus+" tree-plus treeclick'";
62
+ rd[expanded] = false;
63
+ }
64
+ rd[isLeaf] = false;
65
+ }
66
+ twrap += "</div></div>";
67
+ if(!$t.p.loadonce) {
68
+ rd[$t.p.localReader.id] = row.id;
69
+ $t.p.data.push(rd);
70
+ $t.p._index[row.id]=$t.p.data.length-1;
71
+ }
72
+ if(parseInt(rd[level],10) !== parseInt($t.p.tree_root_level,10)) {
73
+ if(!$($t).jqGrid("isVisibleNode",rd)){
74
+ $(row).css("display","none");
75
+ }
76
+ }
77
+
78
+ $("td:eq("+expCol+")",row).wrapInner("<span></span>").prepend(twrap);
79
+ $(".treeclick",row).bind("click",function(e){
80
+ var target = e.target || e.srcElement,
81
+ ind2 =$(target,$t.rows).closest("tr.jqgrow")[0].id,
82
+ pos = $t.p._index[ind2],
83
+ isLeaf = $t.p.treeReader.leaf_field,
84
+ expanded = $t.p.treeReader.expanded_field;
85
+ if(!$t.p.data[pos][isLeaf]){
86
+ if($t.p.data[pos][expanded]){
87
+ $($t).jqGrid("collapseRow",$t.p.data[pos]);
88
+ $($t).jqGrid("collapseNode",$t.p.data[pos]);
89
+ } else {
90
+ $($t).jqGrid("expandRow",$t.p.data[pos]);
91
+ $($t).jqGrid("expandNode",$t.p.data[pos]);
92
+ }
93
+ }
94
+ return false;
95
+ });
96
+ if($t.p.ExpandColClick === true) {
97
+ $("span", row).css("cursor","pointer").bind("click",function(e){
98
+ var target = e.target || e.srcElement,
99
+ ind2 =$(target,$t.rows).closest("tr.jqgrow")[0].id,
100
+ pos = $t.p._index[ind2],
101
+ isLeaf = $t.p.treeReader.leaf_field,
102
+ expanded = $t.p.treeReader.expanded_field;
103
+ if(!$t.p.data[pos][isLeaf]){
104
+ if($t.p.data[pos][expanded]){
105
+ $($t).jqGrid("collapseRow",$t.p.data[pos]);
106
+ $($t).jqGrid("collapseNode",$t.p.data[pos]);
107
+ } else {
108
+ $($t).jqGrid("expandRow",$t.p.data[pos]);
109
+ $($t).jqGrid("expandNode",$t.p.data[pos]);
110
+ }
111
+ }
112
+ $($t).jqGrid("setSelection",ind2);
113
+ return false;
114
+ });
115
+ }
116
+ });
117
+ },
118
+ setTreeGrid : function() {
119
+ return this.each(function (){
120
+ var $t = this, i=0, pico;
121
+ if(!$t.p.treeGrid) { return; }
122
+ if(!$t.p.treedatatype ) { $.extend($t.p,{treedatatype: $t.p.datatype}); }
123
+ $t.p.subGrid = false; $t.p.altRows =false;
124
+ $t.p.pgbuttons = false; $t.p.pginput = false;
125
+ $t.p.multiselect = false; $t.p.rowList = [];
126
+ pico = 'ui-icon-triangle-1-' + ($t.p.direction=="rtl" ? 'w' : 'e');
127
+ $t.p.treeIcons = $.extend({plus:pico,minus:'ui-icon-triangle-1-s',leaf:'ui-icon-radio-off'},$t.p.treeIcons || {});
128
+ if($t.p.treeGridModel == 'nested') {
129
+ $t.p.treeReader = $.extend({
130
+ level_field: "level",
131
+ left_field:"lft",
132
+ right_field: "rgt",
133
+ leaf_field: "isLeaf",
134
+ expanded_field: "expanded",
135
+ loaded: "loaded"
136
+ },$t.p.treeReader);
137
+ } else
138
+ if($t.p.treeGridModel == 'adjacency') {
139
+ $t.p.treeReader = $.extend({
140
+ level_field: "level",
141
+ parent_id_field: "parent",
142
+ leaf_field: "isLeaf",
143
+ expanded_field: "expanded",
144
+ loaded: "loaded"
145
+ },$t.p.treeReader );
146
+ }
147
+ for (var key in $t.p.colModel){
148
+ if($t.p.colModel.hasOwnProperty(key)) {
149
+ if($t.p.colModel[key].name == $t.p.ExpandColumn) {
150
+ $t.p.expColInd = i;
151
+ break;
152
+ }
153
+ i++;
154
+ }
155
+ }
156
+ if(!$t.p.expColInd) { $t.p.expColInd = 0; }
157
+ $.each($t.p.treeReader,function(i,n){
158
+ if(n){
159
+ $t.p.colNames.push(n);
160
+ $t.p.colModel.push({name:n,width:1,hidden:true,sortable:false,resizable:false,hidedlg:true,editable:true,search:false});
161
+ }
162
+ });
163
+ });
164
+ },
165
+ expandRow: function (record){
166
+ this.each(function(){
167
+ var $t = this;
168
+ if(!$t.grid || !$t.p.treeGrid) { return; }
169
+ var childern = $($t).jqGrid("getNodeChildren",record),
170
+ //if ($($t).jqGrid("isVisibleNode",record)) {
171
+ expanded = $t.p.treeReader.expanded_field;
172
+ $(childern).each(function(i){
173
+ var id = $.jgrid.getAccessor(this,$t.p.localReader.id);
174
+ $("#"+id,$t.grid.bDiv).css("display","");
175
+ if(this[expanded]) {
176
+ $($t).jqGrid("expandRow",this);
177
+ }
178
+ });
179
+ //}
180
+ });
181
+ },
182
+ collapseRow : function (record) {
183
+ this.each(function(){
184
+ var $t = this;
185
+ if(!$t.grid || !$t.p.treeGrid) { return; }
186
+ var childern = $($t).jqGrid("getNodeChildren",record),
187
+ expanded = $t.p.treeReader.expanded_field;
188
+ $(childern).each(function(i){
189
+ var id = $.jgrid.getAccessor(this,$t.p.localReader.id);
190
+ $("#"+id,$t.grid.bDiv).css("display","none");
191
+ if(this[expanded]){
192
+ $($t).jqGrid("collapseRow",this);
193
+ }
194
+ });
195
+ });
196
+ },
197
+ // NS ,adjacency models
198
+ getRootNodes : function() {
199
+ var result = [];
200
+ this.each(function(){
201
+ var $t = this;
202
+ if(!$t.grid || !$t.p.treeGrid) { return; }
203
+ switch ($t.p.treeGridModel) {
204
+ case 'nested' :
205
+ var level = $t.p.treeReader.level_field;
206
+ $($t.p.data).each(function(i){
207
+ if(parseInt(this[level],10) === parseInt($t.p.tree_root_level,10)) {
208
+ result.push(this);
209
+ }
210
+ });
211
+ break;
212
+ case 'adjacency' :
213
+ var parent_id = $t.p.treeReader.parent_id_field;
214
+ $($t.p.data).each(function(i){
215
+ if(this[parent_id] === null || String(this[parent_id]).toLowerCase() == "null") {
216
+ result.push(this);
217
+ }
218
+ });
219
+ break;
220
+ }
221
+ });
222
+ return result;
223
+ },
224
+ getNodeDepth : function(rc) {
225
+ var ret = null;
226
+ this.each(function(){
227
+ if(!this.grid || !this.p.treeGrid) { return; }
228
+ var $t = this;
229
+ switch ($t.p.treeGridModel) {
230
+ case 'nested' :
231
+ var level = $t.p.treeReader.level_field;
232
+ ret = parseInt(rc[level],10) - parseInt($t.p.tree_root_level,10);
233
+ break;
234
+ case 'adjacency' :
235
+ ret = $($t).jqGrid("getNodeAncestors",rc).length;
236
+ break;
237
+ }
238
+ });
239
+ return ret;
240
+ },
241
+ getNodeParent : function(rc) {
242
+ var result = null;
243
+ this.each(function(){
244
+ var $t = this;
245
+ if(!$t.grid || !$t.p.treeGrid) { return; }
246
+ switch ($t.p.treeGridModel) {
247
+ case 'nested' :
248
+ var lftc = $t.p.treeReader.left_field,
249
+ rgtc = $t.p.treeReader.right_field,
250
+ levelc = $t.p.treeReader.level_field,
251
+ lft = parseInt(rc[lftc],10), rgt = parseInt(rc[rgtc],10), level = parseInt(rc[levelc],10);
252
+ $(this.p.data).each(function(){
253
+ if(parseInt(this[levelc],10) === level-1 && parseInt(this[lftc],10) < lft && parseInt(this[rgtc],10) > rgt) {
254
+ result = this;
255
+ return false;
256
+ }
257
+ });
258
+ break;
259
+ case 'adjacency' :
260
+ var parent_id = $t.p.treeReader.parent_id_field,
261
+ dtid = $t.p.localReader.id;
262
+ $(this.p.data).each(function(i,val){
263
+ if(this[dtid] == rc[parent_id] ) {
264
+ result = this;
265
+ return false;
266
+ }
267
+ });
268
+ break;
269
+ }
270
+ });
271
+ return result;
272
+ },
273
+ getNodeChildren : function(rc) {
274
+ var result = [];
275
+ this.each(function(){
276
+ var $t = this;
277
+ if(!$t.grid || !$t.p.treeGrid) { return; }
278
+ switch ($t.p.treeGridModel) {
279
+ case 'nested' :
280
+ var lftc = $t.p.treeReader.left_field,
281
+ rgtc = $t.p.treeReader.right_field,
282
+ levelc = $t.p.treeReader.level_field,
283
+ lft = parseInt(rc[lftc],10), rgt = parseInt(rc[rgtc],10), level = parseInt(rc[levelc],10);
284
+ $(this.p.data).each(function(i){
285
+ if(parseInt(this[levelc],10) === level+1 && parseInt(this[lftc],10) > lft && parseInt(this[rgtc],10) < rgt) {
286
+ result.push(this);
287
+ }
288
+ });
289
+ break;
290
+ case 'adjacency' :
291
+ var parent_id = $t.p.treeReader.parent_id_field,
292
+ dtid = $t.p.localReader.id;
293
+ $(this.p.data).each(function(i,val){
294
+ if(this[parent_id] == rc[dtid]) {
295
+ result.push(this);
296
+ }
297
+ });
298
+ break;
299
+ }
300
+ });
301
+ return result;
302
+ },
303
+ getFullTreeNode : function(rc) {
304
+ var result = [];
305
+ this.each(function(){
306
+ var $t = this, len;
307
+ if(!$t.grid || !$t.p.treeGrid) { return; }
308
+ switch ($t.p.treeGridModel) {
309
+ case 'nested' :
310
+ var lftc = $t.p.treeReader.left_field,
311
+ rgtc = $t.p.treeReader.right_field,
312
+ levelc = $t.p.treeReader.level_field,
313
+ lft = parseInt(rc[lftc],10), rgt = parseInt(rc[rgtc],10), level = parseInt(rc[levelc],10);
314
+ $(this.p.data).each(function(i){
315
+ if(parseInt(this[levelc],10) >= level && parseInt(this[lftc],10) >= lft && parseInt(this[lftc],10) <= rgt) {
316
+ result.push(this);
317
+ }
318
+ });
319
+ break;
320
+ case 'adjacency' :
321
+ result.push(rc);
322
+ var parent_id = $t.p.treeReader.parent_id_field,
323
+ dtid = $t.p.localReader.id;
324
+ $(this.p.data).each(function(i){
325
+ len = result.length;
326
+ for (i = 0; i < len; i++) {
327
+ if (result[i][dtid] == this[parent_id]) {
328
+ result.push(this);
329
+ break;
330
+ }
331
+ }
332
+ });
333
+ break;
334
+ }
335
+ });
336
+ return result;
337
+ },
338
+ // End NS, adjacency Model
339
+ getNodeAncestors : function(rc) {
340
+ var ancestors = [];
341
+ this.each(function(){
342
+ if(!this.grid || !this.p.treeGrid) { return; }
343
+ var parent = $(this).jqGrid("getNodeParent",rc);
344
+ while (parent) {
345
+ ancestors.push(parent);
346
+ parent = $(this).jqGrid("getNodeParent",parent);
347
+ }
348
+ });
349
+ return ancestors;
350
+ },
351
+ isVisibleNode : function(rc) {
352
+ var result = true;
353
+ this.each(function(){
354
+ var $t = this;
355
+ if(!$t.grid || !$t.p.treeGrid) { return; }
356
+ var ancestors = $($t).jqGrid("getNodeAncestors",rc),
357
+ expanded = $t.p.treeReader.expanded_field;
358
+ $(ancestors).each(function(){
359
+ result = result && this[expanded];
360
+ if(!result) {return false;}
361
+ });
362
+ });
363
+ return result;
364
+ },
365
+ isNodeLoaded : function(rc) {
366
+ var result;
367
+ this.each(function(){
368
+ var $t = this;
369
+ if(!$t.grid || !$t.p.treeGrid) { return; }
370
+ var isLeaf = $t.p.treeReader.leaf_field;
371
+ if(rc.loaded !== undefined) {
372
+ result = rc.loaded;
373
+ } else if( rc[isLeaf] || $($t).jqGrid("getNodeChildren",rc).length > 0){
374
+ result = true;
375
+ } else {
376
+ result = false;
377
+ }
378
+ });
379
+ return result;
380
+ },
381
+ expandNode : function(rc) {
382
+ return this.each(function(){
383
+ if(!this.grid || !this.p.treeGrid) { return; }
384
+ var expanded = this.p.treeReader.expanded_field;
385
+ if(!rc[expanded]) {
386
+ var id = $.jgrid.getAccessor(rc,this.p.localReader.id);
387
+ var rc1 = $("#"+id,this.grid.bDiv)[0];
388
+ var position = this.p._index[id];
389
+ if( $(this).jqGrid("isNodeLoaded",this.p.data[position]) ) {
390
+ rc[expanded] = true;
391
+ $("div.treeclick",rc1).removeClass(this.p.treeIcons.plus+" tree-plus").addClass(this.p.treeIcons.minus+" tree-minus");
392
+ } else {
393
+ rc[expanded] = true;
394
+ $("div.treeclick",rc1).removeClass(this.p.treeIcons.plus+" tree-plus").addClass(this.p.treeIcons.minus+" tree-minus");
395
+ this.p.treeANode = rc1.rowIndex;
396
+ this.p.datatype = this.p.treedatatype;
397
+ if(this.p.treeGridModel == 'nested') {
398
+ $(this).jqGrid("setGridParam",{postData:{nodeid:id,n_left:rc.lft,n_right:rc.rgt,n_level:rc.level}});
399
+ } else {
400
+ $(this).jqGrid("setGridParam",{postData:{nodeid:id,parentid:rc.parent_id,n_level:rc.level}});
401
+ }
402
+ $(this).trigger("reloadGrid");
403
+ if(this.p.treeGridModel == 'nested') {
404
+ $(this).jqGrid("setGridParam",{postData:{nodeid:'',n_left:'',n_right:'',n_level:''}});
405
+ } else {
406
+ $(this).jqGrid("setGridParam",{postData:{nodeid:'',parentid:'',n_level:''}});
407
+ }
408
+ }
409
+ }
410
+ });
411
+ },
412
+ collapseNode : function(rc) {
413
+ return this.each(function(){
414
+ if(!this.grid || !this.p.treeGrid) { return; }
415
+ if(rc.expanded) {
416
+ rc.expanded = false;
417
+ var id = $.jgrid.getAccessor(rc,this.p.localReader.id);
418
+ var rc1 = $("#"+id,this.grid.bDiv)[0];
419
+ $("div.treeclick",rc1).removeClass(this.p.treeIcons.minus+" tree-minus").addClass(this.p.treeIcons.plus+" tree-plus");
420
+ }
421
+ });
422
+ },
423
+ SortTree : function( sortname, newDir, st, datefmt) {
424
+ return this.each(function(){
425
+ if(!this.grid || !this.p.treeGrid) { return; }
426
+ var i, len,
427
+ rec, records = [], $t = this, query, roots,
428
+ rt = $(this).jqGrid("getRootNodes");
429
+ // Sorting roots
430
+ query = $.jgrid.from(rt);
431
+ query.orderBy(sortname,newDir,st, datefmt);
432
+ roots = query.select();
433
+
434
+ // Sorting children
435
+ for (i = 0, len = roots.length; i < len; i++) {
436
+ rec = roots[i];
437
+ records.push(rec);
438
+ $(this).jqGrid("collectChildrenSortTree",records, rec, sortname, newDir,st, datefmt);
439
+ }
440
+ $.each(records, function(index, row) {
441
+ var id = $.jgrid.getAccessor(this,$t.p.localReader.id);
442
+ $('#'+$t.p.id+ ' tbody tr:eq('+index+')').after($('tr#'+id,$t.grid.bDiv));
443
+ });
444
+ query = null; roots=null;records=null;
445
+ });
446
+ },
447
+ collectChildrenSortTree : function(records, rec, sortname, newDir,st, datefmt) {
448
+ return this.each(function(){
449
+ if(!this.grid || !this.p.treeGrid) { return; }
450
+ var i, len,
451
+ child, ch, query, children;
452
+ ch = $(this).jqGrid("getNodeChildren",rec);
453
+ query = $.jgrid.from(ch);
454
+ query.orderBy(sortname, newDir, st, datefmt);
455
+ children = query.select();
456
+ for (i = 0, len = children.length; i < len; i++) {
457
+ child = children[i];
458
+ records.push(child);
459
+ $(this).jqGrid("collectChildrenSortTree",records, child, sortname, newDir, st, datefmt);
460
+ }
461
+ });
462
+ },
463
+ // experimental
464
+ setTreeRow : function(rowid, data) {
465
+ var success=false;
466
+ this.each(function(){
467
+ var t = this;
468
+ if(!t.grid || !t.p.treeGrid) { return; }
469
+ success = $(t).jqGrid("setRowData",rowid,data);
470
+ });
471
+ return success;
472
+ },
473
+ delTreeNode : function (rowid) {
474
+ return this.each(function () {
475
+ var $t = this;
476
+ if(!$t.grid || !$t.p.treeGrid) { return; }
477
+ var rc = $($t).jqGrid("getInd",rowid,true);
478
+ if (rc) {
479
+ var dr = $($t).jqGrid("getNodeChildren",rc);
480
+ if(dr.length>0){
481
+ for (var i=0;i<dr.length;i++){
482
+ $($t).jqGrid("delRowData",dr[i].id);
483
+ }
484
+ }
485
+ $($t).jqGrid("delRowData",rc.id);
486
+ }
487
+ });
488
+ }
489
+ });
483
490
  })(jQuery);