Browse Source

feat(treegrid extension): fix #3922, add rootParentId option

zhixin 7 years ago
parent
commit
5790b76f0d

+ 1 - 0
CHANGELOG.md

@@ -8,6 +8,7 @@ ChangeLog
 - feat(locale): rewrite all locales to ES6
 - feat(locale): rewrite all locales to ES6
 - feat(editable extension): rewrite bootstrap-table-editable to ES6
 - feat(editable extension): rewrite bootstrap-table-editable to ES6
 - feat(filter-control extension): rewrite bootstrap-table-filter-control to ES6
 - feat(filter-control extension): rewrite bootstrap-table-filter-control to ES6
+- feat(treegrid extension): add `rootParentId` option
 - fix(js): fix #3653, getHiddenRows method bug
 - fix(js): fix #3653, getHiddenRows method bug
 - fix(js): fix #4066, `getOptions` method remove data property
 - fix(js): fix #4066, `getOptions` method remove data property
 - fix(js): fix #4088, no matches display error
 - fix(js): fix #4088, no matches display error

+ 15 - 3
src/extensions/treegrid/README.md

@@ -10,14 +10,26 @@ Use Plugin: [bootstrap-table-treegrid](https://github.com/wenzhixin/bootstrap-ta
 
 
 ## Options
 ## Options
 
 
+### idField
+
+* type: String
+* description: overwrite the default idField to `'id'`
+* default: `'id'`
+
 ### treeShowField
 ### treeShowField
 
 
 * type: String
 * type: String
-* description: 
+* description:
 * default: ``
 * default: ``
 
 
 ### parentIdField
 ### parentIdField
 
 
 * type: String
 * type: String
-* description: 
-* default: `pid`
+* description:
+* default: `'pid'`
+
+### rootParentId
+
+* type: String
+* description:
+* default: `null`

+ 3 - 1
src/extensions/treegrid/bootstrap-table-treegrid.js

@@ -8,6 +8,7 @@
         treeShowField: null,
         treeShowField: null,
         idField: 'id',
         idField: 'id',
         parentIdField: 'pid',
         parentIdField: 'pid',
+        rootParentId: null,
         onGetNodes: function (row, data) {
         onGetNodes: function (row, data) {
             var that = this;
             var that = this;
             var nodes = [];
             var nodes = [];
@@ -20,7 +21,8 @@
         },
         },
         onCheckRoot: function (row, data) {
         onCheckRoot: function (row, data) {
             var that = this;
             var that = this;
-            return !row[that.options.parentIdField];
+            return that.options.rootParentId === row[that.options.parentIdField] ||
+                !row[that.options.parentIdField];
         }
         }
     });
     });