0

I had a table that I filled with the items that backend returns like so:

        <table id="productsTable" class="bg-white table table-striped table-hover nowrap rounded shadow-xs border-xs mt-2" cellspacing="0">
            <thead>
                <tr>
                    @foreach( $field['columns'] as $column )
                    <th style="font-weight: 600!important;">
                        {{ $column }}
                    </th>
                    @endforeach
                </tr>
            </thead>
            <tbody>
                @foreach( $field['items'] as $key => $item )
                <tr>
                    <td>
                        @if($item['checked'])
                            <input type="checkbox" id="checkbox_{{$item['id']}}" product_id="{{$item['id']}}" checked>
                        @else
                            <input type="checkbox" id="checkbox_{{$item['id']}}" product_id="{{$item['id']}}">
                    </td>
                    <td>
                        {{ $item['name'] }}
                    </td>
                    <td>
                        <input type="text" id="menu_name_{{$item['id']}}" style="width: 100%;" readonly>
                    </td>
                    <td>
                        <input class="form-control form-control-sm" type="number" id="price_{{$item['id']}}" step="0.01" min="1" value="{{$item['price']}}">                    
                    </td>
                </tr>
                @endforeach
            </tbody>
          </table>

Which then I turn into datatable and everything works allright.

Problem came when I tried to get the same table but with the data loaded by ajax, all the cells are just text and not the elements I want and had on the table.

Is it possible to have custom cells (to add checkboxes, selects, all kind of input types, etc) with an ajax loaded datatable?

  • _"Is it possible to have custom cells... with an ajax loaded datatable?"_ - Yes it is possible - there are various techniques you can use. Can you [edit] your question to show (a) your attempt, and (b) some of the sample JSON data returned by the Ajax call? – andrewJames Dec 29 '21 at 18:43
  • 1
    There are also questions on SO which cover aspects of this already. One example: [using a column renderer](https://stackoverflow.com/questions/30489307/make-column-data-as-hyperlink-datatable-jquery). – andrewJames Dec 29 '21 at 18:43
  • 1
    You are absolutely right, must have missed it when looking at the docs. Seems to be working with the renderer, thanks! – Miguel Heredia Dec 29 '21 at 19:13
  • Glad you have a solution! Does this answer your question? [make column data as hyperlink (dataTable JQUERY)](https://stackoverflow.com/questions/30489307/make-column-data-as-hyperlink-datatable-jquery) – andrewJames Dec 29 '21 at 19:27
  • Yeah it absolutely does! – Miguel Heredia Dec 30 '21 at 10:28

0 Answers0