Select field when getting data from an ajax request

Select field when getting data from an ajax request

vtcpe12vtcpe12 Posts: 1Questions: 1Answers: 0

Hi,

I'm currently getting data from an ajax request and it is working great. The problem is that I need to add a select field to each row. Is there a method to do so? The select field will be dynamic but will not change from row to row, it is dependent on another parameter that I pass to the ajax request. I have included my initialization of the datatable, it is pretty basic:

const datatable = $('#maint_docs').DataTable({
                    'ajax': url,
                    'rowCallback': function(row, data, index) {
                        const color = '#'+data[8];
                        $(row).find('td:eq(7)').css('background-color', color);
                    },
                    'columnDefs': [
                        {
                            'targets': [8],
                            'visible': false,
                            'searchable': false
                        },
                        {
                            'targets': [9],
                            'searchable': false,
                            'sortable': false
                        }
                    ]
                });

Thanks in advance.

Answers

  • kthorngrenkthorngren Posts: 21,303Questions: 26Answers: 4,947

    Not sure I totally understand what you are trying to do. The Select extension is the easiest way to implement a column for row selection. Take a look through the examples to see if they help:
    https://datatables.net/extensions/select/examples/

    The select field will be dynamic but will not change from row to row, it is dependent on another parameter that I pass to the ajax request.

    Please provide more details. Its not clear to me what your goal is.

    Kevin

This discussion has been closed.