data.replace to format all '/' to '_'.
data.replace to format all '/' to '_'.
BalaKrishnanDhanuskodi
Posts: 45Questions: 17Answers: 0
Happy Evening one and All,
I trying to replace all the slash '/' to '_' of the invoice file data. following is the observation.
data = 'INV/001/002/AXS001'
desiered out = INV_001_002_AXS001
{
targets : 2,
render: function (data, type, row ) {
data_replace = data.replace('/', '_');
return '<a href="invoice/'+data_replace+'.pdf">' + data + '</a>';
},
Option 1 - resulted 'INV_001/002/AXS001' - is not right format
Option -2 - currently using this to get the desired out and I am sure this is not the right code.
{
targets : 2,
render: function (data, type, row ) {
data_replace = data.replace('/', '_');
data_replace1 = data_replace.replace('/', '_');
data_replace2 = data_replace1.replace('/', '_');
data_replace3 = data_replace2.replace('/', '_');
return '<a href="invoice/'+data_replace3+'.pdf">' + data + '</a>';
},
Any help would be grateful.
This question has an accepted answers - jump to answer
This discussion has been closed.
Answers
The js "replace" function requires a "global" parameter if it is to replace more than one instance.
Happy Evening Tangerine,
Following option is not working
data_replace = data.replace('/\//g', '_');
Drop the single quotes around the regex to make it a regex object:
Allan
Thanks Allan,
Hi Allan, the table stuck saying ' Loading...'
Does your browser's console show any errors?
Kevin