Advertisement
PinothyJ

Loading Data Into A KTA Form Table

Oct 15th, 2017
529
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. "use strict"
  2.  
  3. window.F = {};
  4.  
  5. F.addRowNumbers = function(tableName, rowNumName) {                                                 //  Adds row numbers to each field in the given column
  6.     if ( typeof tableName !== "undefined" && typeof rowNumName !== "undefined" ) {
  7.         var items = thisForm.controlManager.getControlByName(tableName).getStore().data.items;
  8.        
  9.         for (var rowNum=1; rowNum<=items.length; ++rowNum) {
  10.             F.setTableData(tableName, rowNum-1, rowNumName, rowNum, (rowNum !== items.length));     //  Last parameter will update table after last row's update
  11.         }
  12.     }
  13. };
  14.  
  15. F.setTableData = function(tableName, row, col, data, noUpdate) {
  16.     var tableStore = thisForm.controlManager.getControlByName(tableName).getStore();                //  Get the store of data
  17.    
  18.     if ( (typeof tableStore.getAt(row)).toLowerCase() !== "undefined" ) {                           //  If row exists
  19.         tableStore.getAt(row).data[col] = data;                                                     //  Update column
  20.         ( noUpdate || tableStore.loadData( F.getFlatData(tableName) ) );                            //  Commit data to DOM, unless asked not to
  21.     }
  22. };
  23.  
  24. F.getFlatData = function(tableName) {                                                               //  returns a table's data in a nested array
  25.     var dataArr = [],
  26.         tableStore = thisForm.controlManager.getControlByName(tableName).getStore();
  27.    
  28.     for (var rowNum=0; rowNum<tableStore.data.items.length; ++rowNum) {
  29.         dataArr.push( tableStore.data.items[rowNum].data );                                         //  push the individual rows of data into the array
  30.     }
  31.    
  32.     return dataArr;
  33. };
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement