DataSelection.js 2.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576
  1. /*
  2. Copyright (c) 2004-2012, The Dojo Foundation All Rights Reserved.
  3. Available via Academic Free License >= 2.1 OR the modified BSD license.
  4. see: http://dojotoolkit.org/license for details
  5. */
  6. if(!dojo._hasResource["dojox.grid.DataSelection"]){ //_hasResource checks added by build. Do not use _hasResource directly in your code.
  7. dojo._hasResource["dojox.grid.DataSelection"] = true;
  8. dojo.provide("dojox.grid.DataSelection");
  9. dojo.require("dojox.grid.Selection");
  10. dojo.declare("dojox.grid.DataSelection", dojox.grid.Selection, {
  11. getFirstSelected: function(){
  12. var idx = dojox.grid.Selection.prototype.getFirstSelected.call(this);
  13. if(idx == -1){ return null; }
  14. return this.grid.getItem(idx);
  15. },
  16. getNextSelected: function(inPrev){
  17. var old_idx = this.grid.getItemIndex(inPrev);
  18. var idx = dojox.grid.Selection.prototype.getNextSelected.call(this, old_idx);
  19. if(idx == -1){ return null; }
  20. return this.grid.getItem(idx);
  21. },
  22. getSelected: function(){
  23. var result = [];
  24. for(var i=0, l=this.selected.length; i<l; i++){
  25. if(this.selected[i]){
  26. result.push(this.grid.getItem(i));
  27. }
  28. }
  29. return result;
  30. },
  31. addToSelection: function(inItemOrIndex){
  32. if(this.mode == 'none'){ return; }
  33. var idx = null;
  34. if(typeof inItemOrIndex == "number" || typeof inItemOrIndex == "string"){
  35. idx = inItemOrIndex;
  36. }else{
  37. idx = this.grid.getItemIndex(inItemOrIndex);
  38. }
  39. dojox.grid.Selection.prototype.addToSelection.call(this, idx);
  40. },
  41. deselect: function(inItemOrIndex){
  42. if(this.mode == 'none'){ return; }
  43. var idx = null;
  44. if(typeof inItemOrIndex == "number" || typeof inItemOrIndex == "string"){
  45. idx = inItemOrIndex;
  46. }else{
  47. idx = this.grid.getItemIndex(inItemOrIndex);
  48. }
  49. dojox.grid.Selection.prototype.deselect.call(this, idx);
  50. },
  51. deselectAll: function(inItemOrIndex){
  52. var idx = null;
  53. if(inItemOrIndex || typeof inItemOrIndex == "number"){
  54. if(typeof inItemOrIndex == "number" || typeof inItemOrIndex == "string"){
  55. idx = inItemOrIndex;
  56. }else{
  57. idx = this.grid.getItemIndex(inItemOrIndex);
  58. }
  59. dojox.grid.Selection.prototype.deselectAll.call(this, idx);
  60. }else{
  61. this.inherited(arguments);
  62. }
  63. }
  64. });
  65. }