javascript - JQuery Using Cell Data to Reform Cells -
i'm using jquery, csvtotable (plugin here: https://code.google.com/p/jquerycsvtotable/ ) plugin convert large csv files tables can manipulate. need attach links relevant each row.
i need convert text in 1 of these rows add link pdf. problem can't seem modify strings. i'm using data found here: http://jsfiddle.net/bstrunk/vacuy/297/
the file names generated system can't edited, i'm stuck using these formats:
- 423-1.pdf
so need convert 2 strings tables formatted so:
4/23/2013
1
to drop year, slashes, , add '-' , digit. i'm able grab table data, can't seem manipulate variables either .replace or .substr
$(document).ready(function () { $("tr td:nth-child(5)").each(function () { var $docket = $('td=eq(5)'); var $td = $(this); var $datadate = $td.substr(0, $td.lastindexof("/")); var $newdatadate = $datadate.replace("/", ""); $td.html('<a html="./docs/' + $newdatadate.text() + '-' + $docket.text() + '.pdf">' + $td.text() + '</a>'); }); });
(edit): sample table data:
<tr><td>13ci401111</td><td>22</td><td>name1</td><td>name2</td><td>4/23/2013</td><td>1</td></tr> <tr><td>13ci401112</td><td>22</td><td>name1</td><td>name2</td><td>4/24/2013</td><td>2</td></tr>
first set table id properly:
<table id="csvtable">
then use right selector select 5th cell in each row:
$("#csvtable tr td:nth-child(5)") //note need tell jquery cells inside `csvtable` otherwise search whole document
dollar sign not required @ beginning of each variable , doesn't have significance, can remove it.
wont work:
var $docket = $('td=eq(5)');
it's telling jquery 6th cell where? should specify parent like:
$("#csvtable tr td:nth-child(6)");
but need next cell 1 selected in each
function, better approach use next()
method select next td directly:
$(this).next('td');
complete code:
$(document).ready(function () { $("#csvtable tr td:nth-child(5)").each(function () { var td = $(this), docket = td.next('td').text(), datadate = td.text(), newdate = datadate.substr(0, datadate.lastindexof('/')).replace("/", ''); td.html('<a href="/docs/' + newdate + '-' + docket + '.pdf">' + datadate + '</a>'); }); });
Comments
Post a Comment