Calling a modal using function

Asked

Viewed 116 times

0

I have a table, which lists driver data, that when clicking a column of the table a modal is triggered.

But I want, when clicking, to be called a function, which returns the modal, and not every time I load the page, already load the modal. Just follow the code. That way, it works perfectly, but it’s getting too slow, that’s why I want to know if there’s like,data-target pass a function calling the modal

<?php


if($PERMOT != 0)
{
        echo "<td><a data-toggle='modal' data-target='#modal-$i'>".number_format($log[0], 3)."</a>             </td>";//Gasto
        echo "<td class=".$classTd."><a data-toggle='modal' data-arget='#modal-$i'>".number_format($log[5], 3)."</a></td>";//Diff
                        }
                        else
                            echo "<td><div>-</div><div>-</div><div>-</div></td>";

                    echo "</tr>";
                echo "</tbody>";
                echo "
                    <div class='modal fade' id='modal-$i'>
                        <div class='modal-dialog modal-lg'>
                            <div class='modal-content'>
                                 <div class='modal-header'>
                                    <h4 class='modal-title'>Documento ".$CODFIL."-".$SERDOC." - ".$NUMDOC." </h4>
                                  </div>
                                  <div class='modal-body'>
                                     ".$log[6]."
                                  </div>
                                  <div class='modal-footer'>
                                      <button type='button' class='btn btn-danger' data-dismiss='modal'>Fechar</button>
                                   </div>                   
                            </div>
                        </div>
                    </div>
                ";

                //echo "<button class='info plus  ' id='".$i."' onclick='moreInf($i, $CODFIL, $SERDOC, $NUMDOC)'></button>";
                $i++;

?>
  • Check if the example of this code helps you: https://answall.com/questions/239981

  • People come in here and dump any code and think they’ll succeed to their problem. When you ask about a problem in your code, you’ll get better answers if you give people code that they can use to reproduce the problem. https://answall.com/help/mcve

  • Another good practice is to mark an answer as accepted if it solved or helped solve your problem.

  • Sorry young man, I’m still learning how to use this tool. You’re not obliged to help if you don’t want to,.

1 answer

0

You can try loading the modal directly with the page with a fake setted isOpen Property when the page loads. You then apply a button with an event/function to modify the isOpen property to open and close Modal.

That way the Modal will already be loaded at the beginning and will be faster to make the transition between Modal being shown and hidden.

  • If you can, supplement your answer with a snippet of code. You can make it easier to test.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.