0
votes

I'm using Datatable to display data and charge a table using an AJAX call to a file stored in a JSON object.

I need that one of columns be a text with a link that opens a modal window.

    "columns": [
        { 'data': 'BATCH'},
        { 'data': 'DATE'},
        { 'data': 'STARTTIME'},
        { 'data': 'FINISHTIME'},
        { 'data': 'STATUS'},
    ]

For example, colum Batch is loaded from JSON file, and I want to be a link that opens a modal window.

Please, where do I write the link, in the JSON, when to load the DataTable, or with the API DataTable?

On the same issue, I have another question. Instead of using a button I used a href and I need to pass a parameter on the links of column, for example a parameter, type, with three values (1, 2 and 3) and if the value of link parameter is 1, when the modal window opens, an HTML table is displayed containing within the tag tbody, and if the value is 2, the content of the HTML tag tbody table of modal window, would be different (the header is always the same).

Any suggestions?, can I do it with a modal window or I need three? (both solutions would be valid).

The most important thing is that the table of modal window, change depending on the link is pressed.

1

1 Answers

2
votes

You're nearly there. There's a render function that you can add to the columns array for the cell you want to edit.

"columns": [
    { 
        'data': 'BATCH',
        'render': function(data){
            return $("<button></button>", {
                "text": data,
                "type": "button",
                "class": "btn btn-primary",
                "data-toggle": "modal",
                "data-target": "#myModal"
            }).prop("outerHTML");
        }
    },
    { 'data': 'DATE'},
    { 'data': 'STARTTIME'},
    { 'data': 'FINISHTIME'},
    { 'data': 'STATUS'}
]