简体   繁体   中英

How do I transfer the data-row-id from my formatter to my modal so I can process the proper record

The data-row-id=\\"" + row.id + "\\" is working as I can see the data-row-id show up in the html. How do I get the value from data-row-id into a PHP variable so that I can delete or edit the record? 在此处输入图片说明 The modals are working just fine, but I need to be able to transfer the data-row-id to my modal for processing when the edit button or the delete button is clicked. This is how my table looks for the current record: 在此处输入图片说明

  <script type="text/javascript">
    $( document ).ready(function() {
            //Basic Example
            $("#data-table").bootgrid({
                css: {
                    icon: 'zmdi icon',
                    iconColumns: 'zmdi-view-module',
                    iconDown: 'zmdi-expand-more',
                    iconRefresh: 'zmdi-refresh',
                    iconUp: 'zmdi-expand-less',
                    iconSearch: 'zmdi-search'
                },
            });
            //Selection
            $("#data-table-selection").bootgrid({
                css: {
                    icon: 'zmdi icon',
                    iconColumns: 'zmdi-view-module',
                    iconDown: 'zmdi-expand-more',
                    iconRefresh: 'zmdi-refresh',
                    iconUp: 'zmdi-expand-less',
                    iconSearch: 'zmdi-search'
                },
                selection: true,
                multiSelect: true,
                rowSelect: true,
                keepSelection: true
            });
    // Command Buttons
    $("#data-table-command").bootgrid({
        css: {
            icon: 'zmdi icon',
            iconColumns: 'zmdi-view-module',
            iconDown: 'zmdi-expand-more',
            iconRefresh: 'zmdi-refresh',
            iconUp: 'zmdi-expand-less'
        },
    formatters: {
        "commands": function (column, row) {
            return "<button type=\"button\" class=\"btn btn-icon btn-primary command-edit\"  data-toggle=\"modal\" data-target=\"#modalEdit\" data-row-id=\"" + row.id + "\"><span class=\"zmdi zmdi-edit\"></span></button> " +
                "<button type=\"button\" class=\"btn btn-icon btn-danger command-delete\" data-toggle=\"modal\" data-target=\"#modalDelete\" data-row-id=\"" + row.id + "\"><span class=\"zmdi zmdi-delete\"></span></button>";
        }
    }
}).on("loaded.rs.jquery.bootgrid", function () {
    /* Executes after data is loaded and rendered */
    $(this).find(".command-edit").click(function (e) {
        $($(this).attr("data-target")).modal("show");
    });
}).on("loaded.rs.jquery.bootgrid", function () {
    /* Executes after data is loaded and rendered */
    $(this).find(".command-delete").click(function (e) {
        $($(this).attr("data-target")).modal("show");
    });
});
});
</script>

You can use $_Get command to set the Variable within an array, you can find more information here: http://php.net/manual/en/reserved.variables.get.php :

<?php
$row.id = $_GET['row.id'];
?>

I figured it out myself by adding:

            var rowid = $(this).data('row-id');

To:

}).on("loaded.rs.jquery.bootgrid", function () {
    /* Executes after data is loaded and rendered */
    $(this).find(".command-edit").click(function (e) {
        $($(this).attr("data-target")).modal("show");
        var rowid = $(this).data('row-id');
    });

Now to figure out how to transfer the value in rowid into a PHP value so I can manipulate the record... I am assuming I have to use Ajax for this, I do not know how to use Ajax, is there anyone who can please help? Thank you!

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM