Foros del Web » Programando para Internet » Jquery »

Colocar enlaces en una columna de las tablas

Estas en el tema de Colocar enlaces en una columna de las tablas en el foro de Jquery en Foros del Web. Hola, tengo una Web donde se generan una tabla apartir de un archivo .CSV, necesito hace un enlace en los datos de una de sus ...
  #1 (permalink)  
Antiguo 16/02/2017, 19:29
 
Fecha de Ingreso: febrero-2003
Mensajes: 233
Antigüedad: 21 años, 2 meses
Puntos: 4
Colocar enlaces en una columna de las tablas

Hola, tengo una Web donde se generan una tabla apartir de un archivo .CSV, necesito hace un enlace en los datos de una de sus columnas (Los resultados), en este caso la 2 (Contando desde cero), lo hice con el siguiente código pero al incrustarlo en la página donde debe ir no me muestra los resultados.

<script type="text/javascript">
$.ajax({
url: 'miArchivo.csv',
dataType: 'text',
}).done(successFunction);


function successFunction(data) {
var allRows = data.split(/\r?\n|\r/);
var table = '<table id=demo>';
for (var singleRow = 0; singleRow < allRows.length; singleRow++) {
if (singleRow === 0) {
table += '<thead>';
table += '<tr>';
} else {
table += '<tr>';
}
var rowCells = allRows[singleRow].split(';');
for (var rowCell = 0; rowCell < rowCells.length; rowCell++) {
if (singleRow === 0) {
table += '<th>';
table += rowCells[rowCell];
table += '</th>';
} else {
table += '<td>';
if (rowCell===2){
table += '<a href=certificado.html?id='+ rowCells[0] + '>';
table += rowCells[rowCell];
table += '</a>';
table += '</td>';
} else {
table += rowCells[rowCell];
table += '</td>';
}
}
}
if (singleRow === 0) {
table += '</tr>';
table += '</thead>';
} else {
table += '</tr>';
}
}
table += '</tbody>';
table += '</table>';
$('body').append(table);
}
</script>

Pero no puedo aplicarla en el siguinte:

<script>

if("pluginAppObj_01/1111.csv".length > 0){

$.ajax({
url: "pluginAppObj_01/1111.csv",
success: function (data){
parseTable(data, {
app_id: 'pluginAppObj_01',
file_path: 'pluginAppObj_01/1111.csv',
alternate: true,
headercolor: '#FF0000',
bordersize: '1',
bordercolor: '#000000',

header_font_size: '12',
header_font_italic: false,
header_font_bold: true,
header_font_family: 'Tahoma',
header_fontcolor: '#FFFFFF',

cell_font_size: '10',
cell_font_italic: false,
cell_font_bold: false,
cell_font_family: 'Tahoma',

fontcolor: '#7D7D7D',
trcolor: '#FFFFFF',
trcolor_alternate: 'rgb(240,240,240)',
paginate: true,
rowscount: '50',
});
}
});
}

function parseTable(data, params){
config ={
skipEmptyLines: true,
dynamicTyping: true,
complete: function (results) {
bodyData = results.data;
headerData = bodyData[0];
bodyData.shift();
createTable(headerData,bodyData, params);
}
}
Papa.parse(data, config);
}

function createTable(headerData, bodyData, params){
var alternate = params.alternate;
var tableHeaderRow = document.getElementById("tableheaderrow-" + params.app_id);
var tableBody = document.getElementById("tablebody-" + params.app_id);
var datatype = "";

//header creation
for (var i = 0; i<headerData.length; i++){
if (/[a-zA-Z]/.test(bodyData[0][i])){
datatype = "";
}
else{
datatype = "numeric";
}
var newth = document.createElement("th");
newth.innerHTML = headerData[i];
newth.id = "th-" + i;
newth.style.background = params.headercolor;
newth.style.border = params.bordersize + "px solid " + params.bordercolor;
newth.style.fontSize = params.header_font_size + "px";
newth.style.fontFamily = params.header_font_family;
newth.style.fontWeight= (params.header_font_bold ? "bold" : "initial");
newth.style.fontStyle= (params.header_font_italic ? "italic" : "initial");
newth.style.color = params.header_fontcolor;
newth.setAttribute("data-type", datatype);
tableHeaderRow.appendChild(newth);
}

//body creation
for (var i = 0; i<bodyData.length; i++){

var newtr = document.createElement("tr");
newtr.id = "tr" + i;
tableBody.appendChild(newtr);

for(var j = 0; j < bodyData[i].length; j++){
var newtd = document.createElement("td");
newtd.innerHTML = bodyData[i][j];
newtd.setAttribute("data-value", bodyData[i][j]);
newtd.id = "td-" + i + "-" + j;
newtd.style.border = params.bordersize + "px solid " + params.bordercolor;
newtd.style.fontSize = params.cell_font_size + "px";
newtd.style.fontFamily = params.cell_font_family;
newtd.style.fontWeight= (params.cell_font_bold ? "bold" : "initial");
newtd.style.fontStyle= (params.cell_font_italic ? "italic" : "initial");
newtd.style.color = params.fontcolor;
newtr.appendChild(newtd);
}
}

$("#table-" + params.app_id + " tbody tr").css("background-color", params.trcolor);
if (alternate){
$("#table-" + params.app_id + " tbody tr:even").css("background-color", params.trcolor_alternate);
}

var pagination = params.paginate;
var table = document.getElementById("table-" + params.app_id);

if (pagination){
table.setAttribute("data-page-size" , params.rowscount);

var pagination_td = "<td colspan='" + headerData.length + "' style='border: " + params.bordersize + "px solid " + params.bordercolor + "'><div class='pagination pagination-centered hide-if-no-paging'></div></td>";
document.getElementById("foots-" + params.app_id).innerHTML = pagination_td;
}else{
table.setAttribute("data-page-size" , bodyData.length);
}
$("#table-" + params.app_id).footable().bind({
'footable_sorted' : function(e) {
// after sorting the rows, we need to repaint the background color if alternate check is true
if (alternate){
$("#table-" + params.app_id + " tbody tr:even").css("background-color", params.trcolor_alternate);
$("#table-" + params.app_id + " tbody tr:odd").css("background-color", params.trcolor);
}
}
});

table.style.border = params.bordersize + "px solid " + params.bordercolor;
}

</script>


En un momento lo hice pero mostró todos los datos de los resultados en enlace y metidos todos en una sola columna.

Etiquetas: columna, enlaces, html, javascript, tablas, text
Atención: Estás leyendo un tema que no tiene actividad desde hace más de 6 MESES, te recomendamos abrir un Nuevo tema en lugar de responder al actual.
Respuesta




La zona horaria es GMT -6. Ahora son las 23:37.