code: function (columns) {
          var i, j, k,
              totalCol = 0,
              flag = [];
  
          for (i = 0; i < columns[0].length; i++) {
              totalCol += columns[0][i].colspan || 1;
          }
  
          for (i = 0; i < columns.length; i++) {
              flag[i] = [];
              for (j = 0; j < totalCol; j++) {
                  flag[i][j] = false;
              }
          }
  
          for (i = 0; i < columns.length; i++) {
              for (j = 0; j < columns[i].length; j++) {
                  var r = columns[i][j],
                      rowspan = r.rowspan || 1,
                      colspan = r.colspan || 1,
                      index = $.inArray(false, flag[i]);
  
                  if (colspan === 1) {
                      r.fieldIndex = index;
                      // when field is undefined, use index instead
                      if (typeof r.field === 'undefined') {
                          r.field = index;
                      }
                  }
  
                  for (k = 0; k < rowspan; k++) {
                      flag[i + k][index] = true;
                  }
                  for (k = 0; k < colspan; k++) {
                      flag[i][index + k] = true;
                  }
              }
          }
      }
docs: http://jsfiddle.net/wenyi/47nz7ez9/3/