Link to home
Start Free TrialLog in
Avatar of Moti Mashiah
Moti MashiahFlag for Canada

asked on

javascript

Hi Guys,

I have this code:

function format(d) {
            // `d` is the original data object for the row
            return '<table cellpadding="5" cellspacing="0" border="0" style="padding-left:50px;">' +
                '<tr>' +
                    '<td>Price:</td>' +
                    '<td>' + '<input type="text" value="d.Price"/>' + '</td>' +
                '</tr>' +
                '<tr>' +
                    '<td>Cost:</td>' +
                    '<td>' + d.Cost + '</td>' +
                '</tr>' +
                '<tr>' +
                    '<td>Extra info:</td>' +
                    '<td>And any further details here (images etc)...</td>' +
                '</tr>' +
            '</table>';
        }

Open in new window


What I'm trying to do is return dynamic value into input. Please look at the code above and this row example:-  '<td>' + '<input type="text" value="d.Price"/>' + '</td>' +
Avatar of Alexandre Simões
Alexandre Simões
Flag of Switzerland image

And what's your question/problem?

---

As a side note, chaining strings like this is a very bad practice due to performance issues.
I understand that it makes it easier to read, but it's far from ideal.
If this is the only piece of code you have that does this and you don't call it a lot of times (like in a loop), it's ok, otherwise you should consider better options.
Avatar of Moti Mashiah

ASKER

Hi ,

Thank you for your answer.

I'm using dataTable and this code taken from there.
Please see this link and let me what do you think I should do:
https://datatables.net/examples/api/row_details.html
Avatar of Shane Krueger
Shane Krueger

Change
from this:  "d.Price"
to this:    "' + d.Price + '"

Open in new window


So it would be:

'<input type="text" value="' + d.Price + '"/>'

Open in new window

ASKER CERTIFIED SOLUTION
Avatar of Julian Hansen
Julian Hansen
Flag of South Africa image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
solved my issue.