Unable to display varied content in modal table

I'm facing an issue with my two bootstrap tables. The first table, table_compras, triggers a modal (table_modal) based on the clicked column. However, I am struggling to refresh the content rows in the table. Here is the code snippet:

HTML:

<div id="modalTable" class="modal fade" tabindex="-1" role="dialog">
            <div class="modal-dialog modal-lg" role="document">
                <div class="modal-content">
                    <div class="modal-header">
                        <h5 class="modal-title">Acumulado por Obra</h5>
                        <button type="button" class="close" data-dismiss="modal" aria-label="Close">
                        <span aria-hidden="true">&times;</span>
                        </button>
                    </div>
                    <div class="modal-body" id="bodyIP">
                        <table id="table_modal" data-detail-view="true" data-checkbox-header="true" data-search="true" 
                                data-search-align="left" data-detail-filter="detailFilter" data-pagination="true">
                            <thead id="thDel">
                                <tr>                                
                                </tr>
                            </thead>
                        </table>
                    </div>
                    <div class="modal-footer">
                        <button type="button" class="btn btn-secondary" data-dismiss="modal">Close</button>
                    </div>
                </div>
            </div>
        </div>

In my JavaScript function, I'm attempting to get the row and column index to populate the modal table. However, when clicking on a different cell, it continues to display the same data rows as the initial cell. I have tried various options without success:

var $table_compras = $('#table_compras')
            var $table = $('#table_modal')

            $(function() {
                $('#modalTable').on('shown.bs.modal', function () {
                    $table.bootstrapTable('resetView');

                })
                $('#modalTable').on('hide.bs.modal', function (e) {
                    //var table = $('#table_modal').DataTable();
                    //table.clear();
                    //$("#table_modal tr").remove();
                    //$('#table_modal').empty();
                    //$(e.target).removeData('bs.modal');
                    $('#table_modal').detach();
                    //$("#table_modal").empty();
                    //$("#table_modal thead").remove();
                    //$('#modalTable').removeData();

                })

            });

            $('#table_compras').on('click-cell.bs.table', function (field, value, row, $el) 
            {
                buildTable2($table, 2, $el.C1, value);                    
                $("#modalTable").modal();

                //alert($el.C1+"-"+$el.C2+"-"+$el.C3+"---"+value);

            });

            function buildTable2($el, cells, ano, mes) 
            {

                var columns = []
                var data = []                       

                columns.push({ field: 'C1', title: 'idObra', sortable: true})
                columns.push({ field: 'C2', title: 'Nombre', sortable: true})
                columns.push({ field: 'C3', title: 'Monto', sortable: true})
                columns.push({ field: 'C4', title: '% Participacion', sortable: true})                  


                {% for obra in cobros_por_obra %}
                    var noMes =  parseInt('{{obra.1}}');
                    noMes = noMes + 1;                        

                    if ('{{obra.0}}' == ano &&  'C' + noMes == mes)
                    {
                        //console.log('C' + noMes, mes);
                        row = {}

                        row['C1'] = '{{obra.2}}';
                        row['C2'] = '{{obra.3}}';
                        row['C3'] = '$' + Number({{obra.4}}).toFixed(2).replace(/\d(?=(\d{3})+\.)/g, '$&,');
                        row['C4'] = Number({{obra.4}}).toFixed(2).replace(/\d(?=(\d{3})+\.)/g, '$&,');

                        data.push(row)
                    }
                {% endfor %}                   

                console.log(data);                 

                $el.bootstrapTable({
                columns: columns,
                data: data,
                detailView: cells > 2,
                onExpandRow: function (index, row, $detail) {
                    /* eslint no-use-before-define: ["error", { "functions": false }]*/
                    //console.log($detail)
                    expandTable($detail, cells - 1, row.C1)
                    }
                });

            }

Answer №1

Finally working like a charm:

Just implemented the following code snippet:

var $bodyContent = $('#contentBody')

and updated all occurrences of $table to $bodyContent:

$('#table_purchases').on('click-cell.bs.table', function (field, value, row, $el) 
            {

                recreateTable($bodyContent.html('<table data-search="true" data-search-align="left" data-detail-filter="detailFilter" data-pagination="true"></table>').find('table'), 2, $el.C1, value);


                $("#modalPurchaseTable").modal();

                //alert($el.C1+"-"+$el.C2+"-"+$el.C3+"---"+value);

            });

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

Extracting a compilation of video content from a YouTube channel through JSON data retrieval

I'm struggling to display the 5 most recent videos (title, updated, thumbnail (hqDefault)) from a specific channel using JSON data. I've tried various guides but can't seem to parse it correctly. Any suggestions on how to achieve this? I&apo ...

Tips on transferring a file (such as PDF, DOC, etc) from a Client application built with React to a server built with Node.js and Express

Client-side To retrieve the PDF, I utilize an input file: <html> <body> <input type="file" id="file_attachments" name="files" onChange=updateAttachments() multiple> </input> <script> function updateAttachments() { let ...

Problem with npm cache causing failure to rebuild the project

While working with Laravel 5.4 and Vue.js, I encountered a syntax error between the 'created' and 'methods' sections in my code. Although I initially fixed this error, it continued to persist. Even after restarting Apache, the error re ...

Element with absolute position does not expand along with scrollable content (over 100%)

In my popup window, the fade element is supposed to stretch to the full width of the screen. However, when the content exceeds 100% of the browser window height, the element does not extend to the full page height. If I set html, body { height: 100%; over ...

Expanding the size of a div using the Bootstrap grid system

I need to customize the width of the date column on my inbox page so that it displays inline without breaking the word. Even when I use white-space: nowrap, the overflow hides it due to the fixed width. I want the name and date classes to be displayed in ...

Uncaught data emitted by Express route not received by socket.io client

I have encountered an issue where the data emitted from a socket in my ExpressJS route file is not being read by the client-side JavaScript. server.js var express = require('express'); var path = require('path'); var app = express(); ...

Preventing attribute or tag cloning in Jquery: What you need to know

I'm having some trouble with JQuery. I want to clone an attribute or tag that is dragged from one div1 to another div2, which is working fine. But the issue arises when I drag or move the position of an existing tag on div2, then the cloning process s ...

Displaying ember component in a separate template from its parent

Consider this scenario: I have an absolutely positioned sidebar containing additional absolute elements. Within the sidebar, there is a button that triggers a menu to appear: <button>Click me</button> {{#if shouldDisplayMenu}} {{view App.M ...

Learn how to calculate and showcase time discrepancies in minutes using Angular2

I am currently working on an Angular app that displays orders using the *ngFor directive. Each order has a datetime field indicating the date it was created. My goal is to implement a timer that shows how long a customer has been waiting for their order ...

Having trouble viewing the data on my D3 graph

As I attempt to replicate a D3 template, the only variation being that I am extracting the JavaScript and JSON data from my Mac. Despite this, upon opening the HTML in Chrome, the data is not visible. It seems that Stackoverflow is not recognizing my HTM ...

Is it possible to dynamically change HTML content by utilizing a JSON file?

Looking to implement a JavaScript loop (using jQuery) that can dynamically populate the HTML file with content from a JSON file based on matching <div> ids to the JSON "id" values. The solution should be scalable and able to handle any number of < ...

Mastering the art of looping through JSON values using AngularJS ng-repeat

Is there a way to use ng-repeat in order to iterate and access the name values: test01, test02, and test03 from my JSON data? Any guidance on how to achieve this using ng-repeat would be greatly appreciated. Thanks in advance! Check out this Fiddle link. ...

Utilize the useRef hook to dynamically retrieve the updated height when children are altered

I am working with an accordion component and using the useRef hook to measure the height of the children. However, I noticed that when I update the content of the children dynamically, the height measurement does not get updated unless I click on the toggl ...

Does Node.js support backward compatibility?

There is a common belief that Node.js is backwards compatible, meaning scripts running in Node.js N should also work in Node.js N+1. I have been unable to find any documentation confirming this assumption. Is there another way to verify compatibility aside ...

What is the best way to arrange numerous objects within an array?

Here is the code snippet I am working with: const info = { detail : { id: "1", name: "aa", category: [ { id:"11", order:0, }, { id:"33", order:5, }, { id: ...

Unable to activate Vue 13 keyCode in a text field using jQuery with Laravel Dusk Testing

I've been grappling with this issue for a few days now. I'm trying to create a Laravel Dusk test that incorporates the Vue.js framework. There's a method that should be triggered when the user hits the ENTER key. I recently discovered that ...

Running Django on macOS Catalina

Each time I execute python manage.py migrate An error appears: ModuleNotFoundError: No module named 'safetobeme' Interestingly, when I search for "safetebeme" on Google, I find nothing related to it. This issue is occurring on Mac Ca ...

The $http function in AngularJS consistently returns undefined instead of the expected value

var result = dataService.makeHttpRequest("GET", "/documents/checkfilename/", null, function (response, status, headers, config) { // I can see `true` if I alert(response); here // I want to return the contents of ...

Exploring the Overlapping of Objects in Three.js

I am dealing with multiple meshes in my code and I am trying to figure out how to make the renderer display the object that should be in front, somewhat similar to what is shown in this example: --> . I have read about render depth, but I am unsure of h ...

What could be causing the malfunction of my Django Rest Framework Search filter mechanism?

After implementing the code, I encountered an issue. Although no errors were displayed and the search button was successfully added to the browsable API, the search functionality itself was not working as expected. Regardless of the input in the search fie ...