';
- $td.html(div + input); //Set new content
- //Set focus to first column
- if (!focused) {
- $td.find('input').focus();
- focused = true;
- }
- });
- SetButtonsEdit(but);
+
+function butRowEdit(but) {
+ //Start the edition mode for a row.
+ var $row = $(but).parents('tr'); //accede a la fila
+ var $cols = $row.find('td'); //lee campos
+ if (ModoEdicion($row)) return; //Ya está en edición
+ //Pone en modo de edición
+ var focused = false; //flag
+ IterarCamposEdit($cols, function ($td) { //itera por la columnas
+ var cont = $td.html(); //lee contenido
+ //Save previous content in a hide
+ var div = '
' + cont + '
';
+
+ var type = 'text';
+ try {
+ type = colsTyp[$td.index()];
+ } catch (ex) {
+
+ }
+ var input = null;
+ if (type === 'select') {
+ try {
+
+ var opts = [];
+ colsSel.forEach(function (idx) {
+ idx[$td.index()].forEach(function (idy) {
+ opts.push(idy);
+ })
+ });
+
+ input = '
';
+
+ } catch (ex) {
+ alert(ex.message);
+ type = 'text';
+ }
+ } else if (type === 'checkbox') {
+ try {
+ var opts = [];
+ try {
+ colsCheck.forEach(function (idx) {
+ try{
+ idx[$td.index()].forEach(function (idy) {
+ opts.push(idy);
+ })
+ }catch (ex2){}
+ });
+ } catch (ex) {
+ opts = ['true', 'false'];
+ }
+
+ input = '
';
+ } catch (ex) {
+ type = 'text';
+ }
+ }
+ if (input == null)
+ input = '
';
+ $td.html(div + input); //Set new content
+ //Set focus to first column
+ if (!focused) {
+ $td.find('input').focus();
+ focused = true;
+ }
+ });
+ SetButtonsEdit(but);
}
+
function butRowDelete(but) { //Elimina la fila actual
- var $row = $(but).parents('tr'); //accede a la fila
- params.onBeforeDelete($row);
- $row.remove();
- params.onDelete();
+ var $row = $(but).parents('tr'); //accede a la fila
+ params.onBeforeDelete($row);
+ $row.remove();
+ params.onDelete();
}
+
//Functions that can be called directly
-function rowAddNew(tabId, initValues=[]) {
- /* Add a new row to a editable table.
- Parameters:
- tabId -> Id for the editable table.
- initValues -> Optional. Array containing the initial value for the
- new row.
- */
- var $tab_en_edic = $("#"+tabId); //Table to edit
- var $rows = $tab_en_edic.find('tbody tr');
- //if ($rows.length==0) {
- //No hay filas de datos. Hay que crearlas completas
- var $row = $tab_en_edic.find('thead tr'); //encabezado
- var $cols = $row.find('th'); //lee campos
- //construye html
- var htmlDat = '';
- var i = 0;
- $cols.each(function() {
- if ($(this).attr('name')=='buttons') {
- //Es columna de botones
- htmlDat = htmlDat + colEdicHtml; //agrega botones
- } else {
- if (i
'+initValues[i]+'';
- } else {
+function rowAddNew(tabId, initValues = []) {
+ /* Add a new row to a editable table.
+ Parameters:
+ tabId -> Id for the editable table.
+ initValues -> Optional. Array containing the initial value for the
+ new row.
+ */
+ var $tab_en_edic = $("#" + tabId); //Table to edit
+ var $rows = $tab_en_edic.find('tbody tr');
+ //if ($rows.length==0) {
+ //No hay filas de datos. Hay que crearlas completas
+ var $row = $tab_en_edic.find('thead tr'); //encabezado
+ var $cols = $row.find('th'); //lee campos
+ //construye html
+ var htmlDat = '';
+ var i = 0;
+ $cols.each(function () {
+ if ($(this).attr('name') == 'buttons') {
+ //Es columna de botones
+ htmlDat = htmlDat + colEdicHtml; //agrega botones
+ } else {
+ if (i < initValues.length) {
+ htmlDat = htmlDat + '' + initValues[i] + ' | ';
+ } else {
htmlDat = htmlDat + ' | ';
- }
- }
- i++;
- });
- $tab_en_edic.find('tbody').append(''+htmlDat+'
');
- /*} else {
- //Hay otras filas, podemos clonar la última fila, para copiar los botones
- var $lastRow = $tab_en_edic.find('tr:last');
- $lastRow.clone().appendTo($lastRow.parent());
- $lastRow = $tab_en_edic.find('tr:last');
- var $cols = $lastRow.find('td'); //lee campos
- $cols.each(function() {
- if ($(this).attr('name')=='buttons') {
- //Es columna de botones
- } else {
- $(this).html(''); //limpia contenido
- }
- });
- }*/
- params.onAdd();
+ }
+ }
+ i++;
+ });
+ $tab_en_edic.find('tbody').append('' + htmlDat + '
');
+ /*} else {
+ //Hay otras filas, podemos clonar la última fila, para copiar los botones
+ var $lastRow = $tab_en_edic.find('tr:last');
+ $lastRow.clone().appendTo($lastRow.parent());
+ $lastRow = $tab_en_edic.find('tr:last');
+ var $cols = $lastRow.find('td'); //lee campos
+ $cols.each(function() {
+ if ($(this).attr('name')=='buttons') {
+ //Es columna de botones
+ } else {
+ $(this).html(''); //limpia contenido
+ }
+ });
+ }*/
+ params.onAdd();
}
-function rowAddNewAndEdit(tabId, initValues=[]) {
-/* Add a new row an set edition mode */
- rowAddNew(tabId, initValues);
- var $lastRow = $('#'+tabId + ' tr:last');
- butRowEdit($lastRow.find('#bEdit')); //Pass a button reference
+
+function rowAddNewAndEdit(tabId, initValues = []) {
+ /* Add a new row an set edition mode */
+ rowAddNew(tabId, initValues);
+ var $lastRow = $('#' + tabId + ' tr:last');
+ butRowEdit($lastRow.find('#bEdit')); //Pass a button reference
}
+
function TableToCSV(tabId, separator) { //Convert table to CSV
- var datFil = '';
- var tmp = '';
- var $tab_en_edic = $("#" + tabId); //Table source
- $tab_en_edic.find('tbody tr').each(function() {
- //Termina la edición si es que existe
- if (ModoEdicion($(this))) {
- $(this).find('#bAcep').click(); //acepta edición
- }
- var $cols = $(this).find('td'); //lee campos
- datFil = '';
- $cols.each(function() {
- if ($(this).attr('name')=='buttons') {
- //Es columna de botones
- } else {
- datFil = datFil + $(this).html() + separator;
- }
- });
- if (datFil!='') {
- datFil = datFil.substr(0, datFil.length-separator.length);
- }
- tmp = tmp + datFil + '\n';
- });
- return tmp;
+ var datFil = '';
+ var tmp = '';
+ var $tab_en_edic = $("#" + tabId); //Table source
+ $tab_en_edic.find('tbody tr').each(function () {
+ //Termina la edición si es que existe
+ if (ModoEdicion($(this))) {
+ $(this).find('#bAcep').click(); //acepta edición
+ }
+ var $cols = $(this).find('td'); //lee campos
+ datFil = '';
+ $cols.each(function () {
+ if ($(this).attr('name') == 'buttons') {
+ //Es columna de botones
+ } else {
+ datFil = datFil + $(this).html() + separator;
+ }
+ });
+ if (datFil != '') {
+ datFil = datFil.substr(0, datFil.length - separator.length);
+ }
+ tmp = tmp + datFil + '\n';
+ });
+ return tmp;
}
+
function TableToJson(tabId) { //Convert table to JSON
- var json = '{';
- var otArr = [];
- var tbl2 = $('#'+tabId+' tr').each(function(i) {
- var x = $(this).children();
- var itArr = [];
- x.each(function() {
- itArr.push('"' + $(this).text() + '"');
- });
- otArr.push('"' + i + '": [' + itArr.join(',') + ']');
- })
- json += otArr.join(",") + '}'
- return json;
-}
\ No newline at end of file
+ var json = '{';
+ var otArr = [];
+ var tbl2 = $('#' + tabId + ' tr').each(function (i) {
+ var x = $(this).children();
+ var itArr = [];
+ x.each(function () {
+ itArr.push('"' + $(this).text() + '"');
+ });
+ otArr.push('"' + i + '": [' + itArr.join(',') + ']');
+ })
+ json += otArr.join(",") + '}'
+ return json;
+}