datatable загружается ajax с разметкой ниже где добавить по клику .order-kp-list брать id у input отправлять ajax c полученным ID открывая модальной окно с полученными данными При закрытии окна модального Выделить background TD то что открывали и убрать в нем с input checked <tbody> <tr class="odd"><td class="sorting_1"><div class="position-relative order-kp-list mb-1" data-order-limit="1"> <input class="form-check-input position-absolute top-50 end-0 me-3 fs-5" type="radio" name="listGroupRadioGrid1" id="listGroupRadioGrid1" value="278"> <label class="list-group-item py-3 pe-5" for="listGroupRadioGrid1"> <strong class="fw-semibold"> 20290</strong> <span class="d-block small opacity-75">ООО «РусАвтоматизация» omts88@rusautomation.ru</span> <span class="badge text-bg-secondary rounded-pill" style="background-color:#4dbd5a !important;">ожидание ответа </span> <span class="badge text-bg-secondary rounded-pill" style="background-color:#6de3c7!important;">КП отправлено</span> </label> </div></td></tr><tr class="even"><td class="sorting_1"><div class="position-relative order-kp-list mb-1" data-order-limit="10"> <input class="form-check-input position-absolute top-50 end-0 me-3 fs-5" type="radio" name="listGroupRadioGrid10" id="listGroupRadioGrid10" value="260"> <label class="list-group-item py-3 pe-5" for="listGroupRadioGrid10"> <strong class="fw-semibold"> 20119</strong> <span class="d-block small opacity-75">ООО «АВАНГАРД» 105@optinstrument.su</span> <span class="badge text-bg-secondary rounded-pill" style="background-color:#4dbd5a !important;">ожидание ответа </span> <span class="badge text-bg-secondary rounded-pill" style="background-color:#79c4f7!important;">Новый запрос</span> </label> </div></td></tr><tr class="odd"><td class="sorting_1"><div class="position-relative order-kp-list mb-1" data-order-limit="11"> <input class="form-check-input position-absolute top-50 end-0 me-3 fs-5" type="radio" name="listGroupRadioGrid11" id="listGroupRadioGrid11" value="275"> <label class="list-group-item py-3 pe-5" for="listGroupRadioGrid11"> <strong class="fw-semibold"> 19705</strong> <span class="d-block small opacity-75">ООО КЕТОН aag@keton.pro</span> <span class="badge text-bg-secondary rounded-pill" style="background-color:#4dbd5a !important;">ожидание ответа </span> <span class="badge text-bg-secondary rounded-pill" style="background-color:#6de3c7!important;">КП отправлено</span> </label> </div></td></tr><tr class="even"><td class="sorting_1"><div class="position-relative order-kp-list mb-1" data-order-limit="12"> <input class="form-check-input position-absolute top-50 end-0 me-3 fs-5" type="radio" name="listGroupRadioGrid12" id="listGroupRadioGrid12" value="272"> <label class="list-group-item py-3 pe-5" for="listGroupRadioGrid12"> <strong class="fw-semibold"> 19724</strong> <span class="d-block small opacity-75">ООО «СИОН» manager4@sioncompany.ru</span> <span class="badge text-bg-secondary rounded-pill" style="background-color:#008dcb !important;"> сделка</span> <span class="badge text-bg-secondary rounded-pill" style="background-color:#6de3c7!important;">КП отправлено</span> </label> </div></td></tr><tr class="odd"><td class="sorting_1"><div class="position-relative order-kp-list mb-1" data-order-limit="13"> <input class="form-check-input position-absolute top-50 end-0 me-3 fs-5" type="radio" name="listGroupRadioGrid13" id="listGroupRadioGrid13" value="271"> <label class="list-group-item py-3 pe-5" for="listGroupRadioGrid13"> <strong class="fw-semibold"> 19719</strong> <span class="d-block small opacity-75">ООО «Новые приборы» info@npribory.by</span> <span class="badge text-bg-secondary rounded-pill" style="background-color:#008dcb !important;"> сделка</span> <span class="badge text-bg-secondary rounded-pill" style="background-color:#6de3c7!important;">КП отправлено</span> </label> </div></td></tr><tr class="even"><td class="sorting_1"><div class="position-relative order-kp-list mb-1" data-order-limit="14"> <input class="form-check-input position-absolute top-50 end-0 me-3 fs-5" type="radio" name="listGroupRadioGrid14" id="listGroupRadioGrid14" value="268"> <label class="list-group-item py-3 pe-5" for="listGroupRadioGrid14"> <strong class="fw-semibold"> 19799</strong> <span class="d-block small opacity-75">ООО Экомашгрупп r.kachalov@ecomg.ru</span> <span class="badge text-bg-secondary rounded-pill" style="background-color:#008dcb !important;"> сделка</span> <span class="badge text-bg-secondary rounded-pill" style="background-color:#74d1ed!important;">Заказ в производстве</span> </label> </div></td></tr><tr class="odd"><td class="sorting_1"><div class="position-relative order-kp-list mb-1" data-order-limit="15"> <input class="form-check-input position-absolute top-50 end-0 me-3 fs-5" type="radio" name="listGroupRadioGrid15" id="listGroupRadioGrid15" value="266"> <label class="list-group-item py-3 pe-5" for="listGroupRadioGrid15"> <strong class="fw-semibold"> 20260</strong> <span class="d-block small opacity-75">ВТОРАЛЮМИНПРОДУКТ ООО ПК panagushin_as@akron-holding.ru</span> <span class="badge text-bg-secondary rounded-pill" style="background-color:#008dcb !important;"> сделка</span> <span class="badge text-bg-secondary rounded-pill" style="background-color:#de7174!important;">Контроль оплаты</span> </label> </div></td></tr><tr class="even"><td class="sorting_1"><div class="position-relative order-kp-list mb-1" data-order-limit="16"> <input class="form-check-input position-absolute top-50 end-0 me-3 fs-5" type="radio" name="listGroupRadioGrid16" id="listGroupRadioGrid16" value="264"> <label class="list-group-item py-3 pe-5" for="listGroupRadioGrid16"> <strong class="fw-semibold"> 20258</strong> <span class="d-block small opacity-75">ООО ОЛНИСА+ z58@olnisa.ru</span> <span class="badge text-bg-secondary rounded-pill" style="background-color:#008dcb !important;"> сделка</span> <span class="badge text-bg-secondary rounded-pill" style="background-color:#6de3c7!important;">КП отправлено</span> </label> </div></td></tr><tr class="odd"><td class="sorting_1"><div class="position-relative order-kp-list mb-1" data-order-limit="17"> <input class="form-check-input position-absolute top-50 end-0 me-3 fs-5" type="radio" name="listGroupRadioGrid17" id="listGroupRadioGrid17" value="262"> <label class="list-group-item py-3 pe-5" for="listGroupRadioGrid17"> <strong class="fw-semibold"> 20175</strong> <span class="d-block small opacity-75">ООО «АЛЬФА-ГИДРО ИНЖИНИРИНГ» sma@alpha-hydro.com</span> <span class="badge text-bg-secondary rounded-pill" style="background-color:#008dcb !important;"> сделка</span> <span class="badge text-bg-secondary rounded-pill" style="background-color:#74d1ed!important;">Заказ в производстве</span> </label> </div></td></tr><tr class="even"><td class="sorting_1"><div class="position-relative order-kp-list mb-1" data-order-limit="18"> <input class="form-check-input position-absolute top-50 end-0 me-3 fs-5" type="radio" name="listGroupRadioGrid18" id="listGroupRadioGrid18" value="261"> <label class="list-group-item py-3 pe-5" for="listGroupRadioGrid18"> <strong class="fw-semibold"> 20158</strong> <span class="d-block small opacity-75">ООО "Прокеш и Ко.РУС" prokes.rus@yandex.ru</span> <span class="badge text-bg-secondary rounded-pill" style="background-color:#008dcb !important;"> сделка</span> <span class="badge text-bg-secondary rounded-pill" style="background-color:#74d1ed!important;">Заказ в производстве</span> </label> </div></td></tr><tr class="odd"><td class="sorting_1"><div class="position-relative order-kp-list mb-1" data-order-limit="19"> <input class="form-check-input position-absolute top-50 end-0 me-3 fs-5" type="radio" name="listGroupRadioGrid19" id="listGroupRadioGrid19" value="279"> <label class="list-group-item py-3 pe-5" for="listGroupRadioGrid19"> <strong class="fw-semibold"> 20659</strong> <span class="d-block small opacity-75">ООО «РусАвтоматизация» omts89@rusautomation.ru</span> <span class="badge text-bg-secondary rounded-pill" style="background-color:#008dcb !important;"> сделка</span> <span class="badge text-bg-secondary rounded-pill" style="background-color:#6de3c7!important;">КП отправлено</span> </label> </div></td></tr><tr class="even"><td class="sorting_1"><div class="position-relative order-kp-list mb-1" data-order-limit="2"> <input class="form-check-input position-absolute top-50 end-0 me-3 fs-5" type="radio" name="listGroupRadioGrid2" id="listGroupRadioGrid2" value="263"> <label class="list-group-item py-3 pe-5" for="listGroupRadioGrid2"> <strong class="fw-semibold"> 20110</strong> <span class="d-block small opacity-75">ОАО "САЛЕО-Кобрин" omto.saleo-kobrin@ya.ru</span> <span class="badge text-bg-secondary rounded-pill" style="background-color:#4dbd5a !important;">ожидание ответа </span> <span class="badge text-bg-secondary rounded-pill" style="background-color:#6de3c7!important;">КП отправлено</span> </label> </div></td></tr>.........</tbody>

To implement the functionality you described, I'll create a JavaScript solution that:

  1. Handles clicks on .order-kp-list elements
  2. Retrieves the ID from the input's value
  3. Sends an AJAX request to fetch data
  4. Displays the data in a modal window
  5. On modal close, highlights the TD background and removes the checked state from the input

I'll assume you're using jQuery (since DataTables typically uses it) and Bootstrap for the modal. Here's the complete solution:

order-list-handler.js
javascript

This script:

  1. Attaches a click handler to .order-kp-list elements
  2. Gets the ID from the radio input's value
  3. Sends an AJAX POST request to a specified endpoint (you'll need to replace '/api/getOrderDetails' with your actual endpoint)
  4. Creates and shows a Bootstrap modal with the response data
  5. When the modal closes, highlights the parent TD with a light gray background and unchecks the radio input
  6. Cleans up by removing the modal from the DOM

To use this:

  1. Make sure you have jQuery and Bootstrap included in your project
  2. Replace '/api/getOrderDetails' with your actual API endpoint
  3. Adjust the modal content structure based on your API response format
  4. Include this script after your DataTable initialization
  5. Ensure your HTML includes the Bootstrap modal CSS/JS dependencies

The modal will display when clicking anywhere on the .order-kp-list div, and the TD will be highlighted with a light gray background when the modal is closed.

Таблица обновляется setInterval(function() { //table.ajax.reload(); table.ajax.reload(null, false); // user paging is not reset on reload }, 58000); как оставить TD background после обновления таблицы ?

To preserve the TD background color after the DataTable is reloaded via setInterval, you need to store the state of highlighted TDs and reapply the background color after each reload. Since DataTables redraws the table on reload, any direct CSS modifications are lost. Here's how you can achieve this:

Solution

  1. Store the IDs of the orders (from the radio input's value) whose TDs have been highlighted in an array or localStorage.
  2. After the table reloads, reapply the background color to the TDs corresponding to those IDs.
  3. Use DataTables' drawCallback or event listeners to handle reapplying the styles post-reload.

Below is the modified code, assuming you're using jQuery and the same HTML structure from your previous question. This builds on the earlier script and integrates with the setInterval reload.

order-list-handler-with-persistent-highlight.js
javascript

Explanation

  1. Storing Highlighted Orders:
    • An array highlightedOrders stores the value attributes (order IDs) of the radio inputs whose TDs were highlighted.
    • The array is persisted in localStorage to survive page refreshes (optional; remove if not needed).
    • When a modal is closed, the order ID is added to highlightedOrders if not already present.
  2. Reapplying Highlights:
    • The applyHighlights function iterates through highlightedOrders and sets the background color for the corresponding TDs using the input's value attribute.
    • This function is called:
      • Initially when the page loads.
      • After every table reload (via table.ajax.reload callback).
      • After every table draw (via draw event listener).
  3. Integration with DataTable Reload:
    • The setInterval reload uses table.ajax.reload with a callback to call applyHighlights after the reload completes.
    • The false parameter ensures paging is preserved.
    • The draw event listener ensures highlights are reapplied if the table is redrawn for other reasons (e.g., sorting, filtering).
  4. Event Delegation:
    • The click handler for .order-kp-list is attached to the document level to handle dynamically loaded rows after reloads.
    • If your DataTable loads new rows with different IDs, the handler will still work.

Setup Instructions

  1. Replace Table ID:
    • Update $('#yourTableId') with the actual ID of your DataTable (e.g., $('#myTable')).
  2. API Endpoint:
    • Replace '/api/getOrderDetails' with your actual endpoint for fetching order details.
  3. Dependencies:
    • Ensure jQuery, DataTables, and Bootstrap are included.
    • The script assumes the same HTML structure as provided (radio inputs with value attributes in .order-kp-list).
  4. Optional: Remove localStorage:
    • If you don't want highlights to persist across page refreshes, remove the localStorage lines and just use the highlightedOrders array.
  5. CSS:
    • The background color is set to #f0f0f0 (light gray). Adjust as needed.

Notes

  • If the table data changes (e.g., order IDs are removed), you may need to clean up highlightedOrders to remove obsolete IDs. You could add logic in applyHighlights to verify if the order ID still exists in the table.
  • If performance is a concern with many highlighted rows, consider using a CSS class instead of inline styles:
javascript
// Add class instead of inline style $input.closest('td').addClass('highlighted-td'); // In applyHighlights $(`input[value="${orderId}"]`).closest('td').addClass('highlighted-td'); // CSS .highlighted-td { background-color: #f0f0f0 !important; }

This solution ensures that TD backgrounds remain highlighted after table reloads while maintaining the modal and radio input functionality from your original setup.

без localStorage возможно ?

Yes, it's possible to maintain TD background highlights after DataTable reloads without using localStorage by keeping the highlighted order IDs in a JavaScript array that persists for the session. The array will be reset on page refresh, but it will work seamlessly with the setInterval reloads. Below is the updated script, removing localStorage and keeping the same functionality otherwise.

order-list-handler-with-persistent-highlight.js
javascript

Changes Made

  1. Removed localStorage:
    • Replaced JSON.parse(localStorage.getItem('highlightedOrders')) || [] with let highlightedOrders = [];.
    • Removed localStorage.setItem('highlightedOrders', JSON.stringify(highlightedOrders));.
    • The highlightedOrders array now exists only in memory during the page session.
  1. Preserving Functionality:
    • The script still tracks highlighted order IDs in the highlightedOrders array.
Как Grok может помочь?