0

I have created an ASP.net MVC app and I have created a DataTable [DataTable.net] as follows:

<table id="invoiceTable">
    <thead>
        <tr>
            <th>Invoice ID</th>
            <th>Date</th>
            <th>Reciept Date</th>
            <th>Category</th>
            <th>Total Value</th>
            <th>Invoice Ref</th>
            <th>Client</th>
            <th>Status</th>
        </tr>
    </thead>
    <tbody>
        @{
            foreach (FreeAgentApp.Models.CustomInvoice _invoice in ViewBag.Invoices)
            {
                <tr>
                    <td>@_invoice.InvoiceId</td>
                    <td>@_invoice.Date</td>
                    <td>@_invoice.RecpDate</td>
                    <td>@_invoice.Category</td>
                    <td>@_invoice.TotalValue</td>
                    <td>@_invoice.InvoiceRef</td>
                    <td>@_invoice.Client</td>
                    <td>@_invoice.Status</td>
                </tr>
            }
        }
    </tbody>
</table>

And i can get the information from a row when its selected using javascript as follows:

// Row data
    $(document).ready(function () {
        oTable = $('#invoiceTable').dataTable();

        oTable.$('tr').click(function () {
            var data = oTable.fnGetData(this);
            alert(data);
            // ... do something with the array / object of data for the row
        });
    });

The variable data will provide a string of every value in the row separated by a comma as follows:

"000,26-01-14,27-01-14,001,1000,inv,something ltd,paid"

I want to have all these values separated. Note this could be done by splitting on the comma however a value in the table could contain commas.

How can I separate this string?

1 Answer 1

1

According to the DataTables documentation oTable.fnGetData(this); return an array filled with the data of the definitions in the row so you should be able to acces the data directly from data.

var invoiceId = data[0];
var date = data[1];
var recpDate = data[2];

// etc. etc.
Sign up to request clarification or add additional context in comments.

2 Comments

I did say I don't want to split on the comma. What if the data from table contains a comma?
yea its datatables.net - your answer is correct unless a value has a comma in it e.g "00,00" could be a value

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.