There is a modal in the datatable line and a datatable inside this modal.

There is a modal in the datatable line and a datatable inside this modal.

mahmer07mahmer07 Posts: 2Questions: 1Answers: 0
edited October 2021 in DataTables

The following code makes a datatable listing.
I do the listing just fine.
But I have a modal inside a line.

There is one more datatable inside this modal. When I click the button, the modal opens, but it either brings the first record or the last record. i.e. it brings the end or the beginning of the loop

                {
                targets: 6,
                data: null,
                className: "text-left",
                render: function (data, type, row, meta) 
                {

                    label="";
                    label += '<button class="btn btn-primary btn-sm default-btn " id="modalbtn"  data-toggle="modal"  onclick="recete_kisi_detay(this.value);" value="'+row.user_code+'" data-target="#recete_detay'+row.user_code+'">'+
                    '<i class="fas fa-user-edit mr-1" style="font-size: 12px;"></i>Detay</button>'+
                    ' <button class="btn btn-danger btn-sm default-btn" data-toggle="modal" data-target="#recete_sil'+row.user_code+'">'+
                    '<i class="icon-trash mr-1" style="font-size: 12px;"></i>Sil</button>';
                    label += '<div id="recete_detay'+row.user_code+'" class="modal fade" tabindex="-1">'+
                    '<div class="modal-dialog  modal-xl">'+
                        '<div class="modal-content">'+
                            '<div class="modal-header bg-primary text-white">'+
                                '<h6 class="modal-title"><b> '+row.user_name_surname+' <i class="icon-arrow-right13 mr-1 icon-1x"></i></b> isimli hastaya ait reçete geçmişi.</h6>'+
                                '<button type="button" class="close" data-dismiss="modal">&times;</button>'+
                            '</div>'+
                            '<div class="modal-body">'+
                                '<table class="table recete_table_in"  style="width:100%">'+
                                    '<thead>'+
                                        '<tr>'+
                                            '<th>Id</th>'+
                                            '<th>Reçete Adı</th>'+
                                            '<th>Tanı</th>'+
                                            '<th>Tarih</th>'+
                                            '<th>Doktor</th>'+
                                            '<th>işlem</th>'+
                                        '</tr>'+
                                    '</thead>'+
                                '</table>'+
                            '</div>'+
                            '<div class="modal-footer">'+
                                '<button type="button"  class="btn btn-link" data-dismiss="modal">Kapat</button>'+
                            '</div>'+
                        '</div>'+
                    '</div>'+
                '</div>';
                return label;


                },

For the sake of clarity, I only added the part of the columnDefs that I had the problem with, the other parts are in the same logic.

Answers

  • colincolin Posts: 15,142Questions: 1Answers: 2,586

    We're happy to take a look, but as per the forum rules, please link to a test case - a test case that replicates the issue will ensure you'll get a quick and accurate response. Information on how to create a test case (if you aren't able to link to the page you are working on) is available here.

    Cheers,

    Colin

  • mahmer07mahmer07 Posts: 2Questions: 1Answers: 0

    hi colin, i solved this problem last night. I clearly understood the problem.
    Let me post the solution for this, maybe it will be a solution for others looking for help.

    The problem I was having was not a looping issue.

    was the datatable id filled in the relevant modal. When I clicked the button, the datatable was triggered and filled the modal. but it always brought the same data because they had the same id.

    I learned that if you want to use modal or datatable in a set of datatables, we need to give Unique IDs, Classes. So we have to add an id variable for each datatable.

    I will add a working example of this here in 1-2 days, maybe it will be needed for someone doing research. Please do not close the issue within 3 days. Thanks.

Sign In or Register to comment.