SelectionGridWidget.js 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687
  1. /*##############################################################################
  2. # HPCC SYSTEMS software Copyright (C) 2012 HPCC Systems.
  3. #
  4. # Licensed under the Apache License, Version 2.0 (the "License");
  5. # you may not use this file except in compliance with the License.
  6. # You may obtain a copy of the License at
  7. #
  8. # http://www.apache.org/licenses/LICENSE-2.0
  9. #
  10. # Unless required by applicable law or agreed to in writing, software
  11. # distributed under the License is distributed on an "AS IS" BASIS,
  12. # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  13. # See the License for the specific language governing permissions and
  14. # limitations under the License.
  15. ############################################################################## */
  16. define([
  17. "dojo/_base/declare",
  18. "dojo/_base/lang",
  19. "dojo/store/Memory",
  20. "dojo/store/Observable",
  21. "dijit/registry",
  22. "dgrid/OnDemandGrid",
  23. "dgrid/Keyboard",
  24. "dgrid/Selection",
  25. "dgrid/editor",
  26. "dgrid/selector",
  27. "dgrid/extensions/ColumnResizer",
  28. "dgrid/extensions/DijitRegistry",
  29. "hpcc/_Widget",
  30. "dojo/text!../templates/SelectionGridWidget.html",
  31. "dijit/layout/BorderContainer",
  32. "dijit/layout/ContentPane"
  33. ], function (declare, lang, Memory, Observable,
  34. registry,
  35. OnDemandGrid, Keyboard, Selection, editor, selector, ColumnResizer, DijitRegistry,
  36. _Widget,
  37. template) {
  38. return declare("SelectionGridWidget", [_Widget], {
  39. templateString: template,
  40. store: null,
  41. idProperty: "Change Me",
  42. constructor: function (args) {
  43. this.inherited(arguments);
  44. },
  45. postCreate: function (args) {
  46. this.inherited(arguments);
  47. this.borderContainer = registry.byId(this.id + "BorderContainer");
  48. },
  49. resize: function (args) {
  50. this.inherited(arguments);
  51. this.borderContainer.resize();
  52. },
  53. startup: function (args) {
  54. this.inherited(arguments);
  55. },
  56. // Implementation ---
  57. createGrid: function (args) {
  58. this.idProperty = args.idProperty;
  59. var store = new Memory({
  60. idProperty: this.idProperty,
  61. data: []
  62. });
  63. this.store = Observable(store);
  64. this.grid = new declare([OnDemandGrid, Keyboard, Selection, ColumnResizer, DijitRegistry])({
  65. store: this.store,
  66. columns: args.columns
  67. }, this.id + "Grid");
  68. },
  69. setData: function (data) {
  70. this.store.setData(data);
  71. this.grid.refresh();
  72. }
  73. });
  74. });