Dashboard sipadu mbip
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

rows-only.js 1.9KB

123456789101112131415161718192021222324252627282930313233343536373839404142
  1. document.addEventListener("DOMContentLoaded", function() {
  2. function isEmptyRow(instance, row) {
  3. for (var rowData = instance.getData()[row], i = 0, ilen = rowData.length; i < ilen; i++)
  4. if (null !== rowData[i]) return !1;
  5. return !0
  6. }
  7. function defaultValueRenderer(instance, td, row, col, prop, value, cellProperties) {
  8. var args = arguments;
  9. null === args[5] && isEmptyRow(instance, row) ? (args[5] = tpl[col], td.style.color = "#999") : td.style.color = "", Handsontable.renderers.TextRenderer.apply(this, args)
  10. }
  11. var hot1, tpl = ["one", "two", "three"],
  12. data = [
  13. ["", "Kia", "Nissan", "Toyota", "Honda"],
  14. ["2014", 10, 11, 12, 13],
  15. ["2015", 20, 11, 14, 13],
  16. ["2016", 30, 15, 12, 13]
  17. ],
  18. container = document.getElementById("populating");
  19. hot1 = new Handsontable(container, {
  20. startRows: 8,
  21. startCols: 5,
  22. minSpareRows: 1,
  23. contextMenu: !0,
  24. cells: function(row, col, prop) {
  25. var cellProperties = {};
  26. return cellProperties.renderer = defaultValueRenderer, cellProperties
  27. },
  28. beforeChange: function(changes) {
  29. var i, c, instance = hot1,
  30. ilen = changes.length,
  31. clen = instance.colCount,
  32. rowColumnSeen = {},
  33. rowsToFill = {};
  34. for (i = 0; i < ilen; i++) null === changes[i][2] && null !== changes[i][3] && isEmptyRow(instance, changes[i][0]) && (rowColumnSeen[changes[i][0] + "/" + changes[i][1]] = !0, rowsToFill[changes[i][0]] = !0);
  35. for (var r in rowsToFill)
  36. if (rowsToFill.hasOwnProperty(r))
  37. for (c = 0; c < clen; c++) rowColumnSeen[r + "/" + c] || changes.push([r, c, null, tpl[c]])
  38. }
  39. }), hot1.loadData(data)
  40. });