How to render a format with html input field

How to render a format with html input field

dtbaccountdtbaccount Posts: 5Questions: 1Answers: 0

To create my table, I use HTML table element.
I use language for decimals and thousands.
This works perfect if I use just a value in my cell: <td>50.000,00</td>
When I use this cell as an input field: <input type="number" class="bp-cell" id="myId" value="50.000,00">
it fails.

Any suggestion?

Answers

  • colincolin Posts: 15,240Questions: 1Answers: 2,599

    We're happy to take a look, but as per the forum rules, please link to a test case - a test case that replicates the issue will ensure you'll get a quick and accurate response. Information on how to create a test case (if you aren't able to link to the page you are working on) is available here.

    Cheers,

    Colin

  • dtbaccountdtbaccount Posts: 5Questions: 1Answers: 0

    Hi Colin, thanks for the quick response. I tried to create a test case.
    When you remove {"targets":2, render: $.fn.dataTable.render.number( ',', '.', 2, '$' )} in columndefs, you will have the unformatted number. (The render works when i don't use an input field in html. (I didn't do the css)

  • colincolin Posts: 15,240Questions: 1Answers: 2,599

    Ah, I see, thank you for the test case. But yep, that rendering won't work with an input element - that rendering is purely for test in the <td> elements. That said, you could do something like this SO thread,

    colin

  • dtbaccountdtbaccount Posts: 5Questions: 1Answers: 0

    Hi Colin,
    Thanks for your answer. I didn't find my solution yet, maybe I overlook something.
    The currency mark is less important, but the thousands symbol is.
    for decimals, I can change it by language [decimal:","] . This works
    But with thousands, I add it too in language, but it doesn't present on my datatable. (I still use the input field)

  • kthorngrenkthorngren Posts: 21,336Questions: 26Answers: 4,953

    Datatables won't parse the input elements in the cells to format numbers. You will need to use a Javascript based solution. This SO answer looks interesting. Change the toLocaleString() to the locale you want to use.

    Kevin

Sign In or Register to comment.