Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8971233
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T17:54:30+00:00 2026-06-15T17:54:30+00:00

I am using datatables to show data from a mySQL database. What I want

  • 0

I am using datatables to show data from a mySQL database. What I want to do is capture the value of the current row and show it in a modal for editing.

This is how I am getting the data into Datatable,

$(document).ready(function() {
                $('#loading-span7').fadeOut();
                $('#loading-span5').fadeOut();
                $('#add-company').hide();

                $.fn.dataTableExt.sErrMode = 'throw';

                $('#company').dataTable({
                    "bProcessing" : true,
                    "bServerSide" : true,
                    "sAjaxSource" : "/index.php/company/profile_data",
                    "sDom" : "<'row'<'span6'l><'span6'f>r>t<'row'<'span6'i><'span6'p>>",
                    "sPaginationType" : "bootstrap",
                    "aoColumns" : [{
                        "mData" : "id"
                    }, {
                        "mData" : "name"
                    }, {
                        "mData" : "package_id"
                    }, {
                        "mData" : function(oObj) {
                            return "<a href=\"#\" data-id=\"" + oObj.id + "\" data-name=\"" + oObj.name + "\" role=\"button\" class=\"btn edit-company\">Edit</a></td>";

                        }
                    }, {
                        "mData" : function(oObj) {
                            return "<a href=\"#\" data-id=\"" + oObj.id + "\"  data-name=\"" + oObj.name + "\" role=\"button\" class=\"btn view-users\" >Users</a></td>";
                        }
                    }]
                });

                $.extend($.fn.dataTableExt.oStdClasses, {
                    "sWrapper" : "dataTables_wrapper form-inline"
                });

And here is the modal,

<div id="edit_company" class="modal hide fade" tabindex="-1" role="dialog" aria-labelledby="myModalLabel" aria-hidden="true">
        <div class="modal-header">
            <button type="button" class="close" data-dismiss="modal" aria-hidden="true">
                ×
            </button>
            <h3 id="myModalLabel"><span id="company-label"></span>Company</h3>
        </div>
        <div class="modal-body">
            <form id="company-form">
                <fieldset>
                    <label>Name</label>
                    <input type="text" placeholder="Type something…" name="company-name">
                    <label>Package</label>
                    <select name="package" name="package-id" id="package-id">

                    </select>

                </fieldset>
            </form>

        </div>
        <div class="modal-footer">
            <button class="btn" data-dismiss="modal" aria-hidden="true">
                Close
            </button>
            <button class="btn btn-primary">
                Save changes
            </button>
        </div>
    </div>

And here is the script that I tried to achieve the goal, the problem however is only the first row of the datatable gets captured into the modal

$('#company .edit-company').live('click', function() {
                    var id = $(this).attr('id');
                    $('#company-label').html('Edit ');
                    $('#company-form')[0].reset();
                    $.ajax({
                        url : '/index.php/company/profile_data',
                        type : 'POST',
                        data : 'companies[]=' + id,
                        beforeSend : function() {
                            $('#loading-span7').show();

                        },
                        success : function(data, textStatus, xhr) {

                            var details = JSON.parse(data);
                            console.log(details);
                            //console.log(details.aaData[0].homepage_url);
                            $('input[name=company-name]').val(details.aaData[0].name);
                            //$('input[name=package-id]').html(details.aaData[0].package_id);

                            /**oTable.$('.edit-company').click(function() {
                                var data1 = oTable.fnRowSelected(this);
                                $('input[name=company-name]').val(details.aaData[0].name);

                            });**/
                            var option1 = $('<option />', {
                                text : details.aaData[0].package_id
                            }), option2 = $('<option />', {
                                text : details.aaData[1].package_id
                            });

                            $('select#package-id').append(option1, option2);
                            //$('select#package-id option').text(details.aaData[0].package_id);

                            //$('#package-id').val(details.aaData[0].package_id);
                            $('#edit_company').modal('show');
                            $('#loading-span7').fadeOut();
                        },
                        error : function(xhr, textStatus, errorThrown) {
                            //alert('error');
                        }
                    });

                });

What can I do to achieve my goal?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-15T17:54:31+00:00Added an answer on June 15, 2026 at 5:54 pm

    Since you’re using bServerSide, just use the fnRowCallback and format your columns slightly differently.

    "fnRowCallback": function(nRow, aData, iDisplayIndex, iDisplayIndexFull) {
        var row = $(nRow),
            a = $('<a />').addClass('btn').attr({
                'href': '#',
                "role": "button"
            }).data('rowData', { //store the data in the button
            "id": aData[0],
            "name": aData[1],
            "package_id": aData[2]
        });
        // or store the raw data in the tr element
        //row.data('rowData', aData);
        // or store a formtted object containing the raw data in the tr element
        //row.data('rowData', );
        // Add the Edit button when the datatable draws the row.
        row.find('td:eq(3)').append(a.clone().addClass('edit-company').text('Edit').click(function (e) {
            var self = $(this),
                rowData = self.data('rowData'),
                id = rowData.id,
                name = rowData.name,
                package_id = rowData.package_id;
            //code to init your dialog
            e.preventDefault();
            return false;
        }));
        // Add the Users button when the datatable draws the row.
        row.find('td:eq(4)').append(a.clone().addClass('view-users').text('Users').click(function (e) {
            var self = $(this),
                rowData = self.data('rowData'),
                id = rowData.id,
                name = rowData.name,
                package_id = rowData.package_id;
            //code to handle your users
            e.preventDefault();
            return false;
        }));
    },
    "aoColumns" : [{
        "mData" : "id"
    }, {
        "mData" : "name"
    }, {
        "mData" : "package_id"
    }, {
        "mData" : "Edit"
    }
    }, {
        "mData" : "Users"
    }]
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

i want to show my input data from DB...i'm interest for using jquery dataTable...
i want to show the data from the database onto my datagridview control i
I am using an API to get data from a mySQL database in a
I am using this jquery datatable plugin to display information from database. My table
I'm using webgrid to show data from my data base. The problem is that
Im trying to select data from oracle database and show it in DataGridView .
Hi I am trying to load table from MySQL database and show contents of
I am using DataTables with server-side processing with information from a form. On form
Here's the code I'm using to show the Excel data on a Gridview: if
I need a fastest solution for transferring data from XML file to MySQL tables.

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.