CustomCol.js 1.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748
  1. /**
  2. * Created by Jacky.gao on 2016/9/18.
  3. */
  4. import Col from './Col.js';
  5. export default class CustomCol extends Col{
  6. constructor(table,name,width){
  7. super(table);
  8. this.customCells=[];
  9. this.name=name;
  10. this.width=width || 160;
  11. this.type='custom';
  12. this.init();
  13. }
  14. init(){
  15. const _this=this;
  16. this.td=$(`<td style="width:${this.width}px;background: #dbfd60;border:1px solid #607D8B;padding-right: 0px">${this.name}</td>`);
  17. const del=$("<span style='color: #999;margin-left: 4px;cursor: pointer'><i class='glyphicon glyphicon-remove'></i></span>");
  18. this.td.append(del);
  19. del.click(function () {
  20. bootbox.confirm("真的要删除当前列?",function (result) {
  21. if(!result)return;
  22. _this.remove();
  23. });
  24. });
  25. this.td.append(this.buildColResizeTrigger());
  26. for(let row of this.scoreCardTable.attributeRows){
  27. row.addCustomCol(this);
  28. }
  29. this.scoreCardTable.headerRow.append(this.td);
  30. this.bindColResize();
  31. }
  32. remove(){
  33. for(let row of this.scoreCardTable.attributeRows){
  34. row.removeCustomCol(this);
  35. }
  36. const pos=this.scoreCardTable.customCols.indexOf(this);
  37. this.scoreCardTable.customCols.splice(pos,1);
  38. for(let cell of this.customCells){
  39. cell.td.remove();
  40. }
  41. this.td.remove();
  42. window._setDirty();
  43. }
  44. toXml(){
  45. let xml="<custom-col col-number=\""+this.getColNumber()+"\" name=\""+this.name+"\" width=\""+this.width+"\"/>";
  46. return xml;
  47. }
  48. }