Output ajax data to your template
Output ajax data to your template

<tr class="product__element">
<td>' . $row['1'] . '</td>
<td>' . $row['2'] . '</td>
<td><a data-fancybox="images" data-caption="' . $row['3'] . '" href="i/' . $row['7'] . '.webp"><img loading="lazy" class="product__img" src="i/' . $row['7'] . '.webp" alt="' . $row['3'] . ' texttexttext" title="' . $row['3'] . '" ></a></td>
<td class="product__name">' . $row['3'] . '</td>
<td>' . $row['4'] . '</td>
<td>' . $row['5'] . '</td>
<td class="product__price">' . $row['6'] . '</td>
<td><div class="product__quantity"></div></td>
<td><button class="product__add-to-cart-button" data-sb-id-or-vendor-code="' . $row['0'] . '" data-sb-product-name="' . $row['3'] . '" data-sb-product-price="' . $row['6'] . '" data-sb-product-quantity="1" data-sb-product-img="i/' . $row['7'] . '.webp"><i class="fas fa-cart-plus"></i></button></td>
</tr>
But this is a slow decision. Please tell me how to do this using Ajax?
Ajax data:
[
"a01634", // $row['0']
"\u0421\u0430\u043c\u043e\u0440\u0435\u0437\u044b", // $row['1']
"\u0421\u0430\u043c\u043e\u0440\u0435\u0437\u044b \u043a\u0440\u043e\u0432\u0435\u043b\u044c\u043d\u044b\u0435 \u043e\u0446\u0438\u043d\u043a\u043e\u0432\u0430\u043d\u043d\u044b\u0435 6,3 \u043c\u043c", // $row['2']
"\u0421\u0430\u043c\u043e\u0440\u0435\u0437\u044b \u043a\u0440\u043e\u0432\u0435\u043b\u044c\u043d\u044b\u0435 \u043e\u0446\u0438\u043d\u043a\u043e\u0432\u0430\u043d\u043d\u044b\u0435 6.3\u0445175", // $row['3']
"6.3\u0445175", // $row['4']
"\u0448\u0442.", // $row['5']
"9.8", // $row['6']
"gvozdiershenye" // $row['7']
]
The most appropriate one was: https://datatables.net/reference/option/ajax however, the example did not help me understand what to do in my case - some columns should display data from several database fields. Strings (TR) must be of the "product__element"class.
Edited by Colin - Syntax highlighting. Details on how to highlight code using markdown can be found in this guide.
This discussion has been closed.
Replies
I don't understand your question at all which doesn't prevent me from answering it
The only thing I understand is this:
And I can answer this question:
You do that with columns.render: https://datatables.net/reference/option/columns.render
Here is an example from my own coding using multiple database fields returned from the server: ctr.ctr_name, ctr.serial, ctr.purpose, ctr.soft_deleted and ctr.expired.
Just as a hint: It helps typing your question into something like Google Translate or even better: deepl.com - to have it translated into English. English is not my first language either.
Just did it with the previous paragraph and translated it into German using deepl.com which is far better than Google. Well, that's comprehensible German to me!