0

I am trying to display json data in bootstrap model table. with ajax call I am puling the data from database and my controller returns the data in json format. I tried to populate the json data into my model table. I dont know whats wrong. Can any body help me in this.

My model table

<div class="modal fade" id="modalTable" tabindex="-1" role="dialog" aria-labelledby="myModalLabel" aria-hidden="true">
    <div class="modal-dialog">
        <div class="modal-content">
            <div class="modal-header">
               
            </div>
            <div class="modal-body">
                <table id="popupTable" class="table-nonfluid" data-toggle="table" data-height="450"     width="450">
                    <thead>
                        <tr>
                            <th class="col-xs-1" data-field="countryCode">Country Code</th>
                            <th class="col-xs-1" data-field="Number"> Number</th>
                            <th class="col-xs-2" data-field="errorMessage">Error Message</th>
                            <th class="col-xs-1" data-field="countryCode">Country Code</th>
                            <th class="col-xs-6" data-field="jobId"> job Id</th>
                            <th class="col-xs-2" data-field="organizationName">Organization Name</th>
                         </tr>
                    </thead>
                  
                </table>
            </div>
            <div class="modal-footer">
                <button type="button" class="btn btn-default" data-dismiss="modal">Close</button>
            </div>
        </div>
        <!-- /.modal-content -->
    </div>
    <!-- /.modal-dialog -->
</div>
<!-- /.modal -->

I have a dataTabe like thisenter image description here

When I click on the number I should show me another table that is a popup. I have given the popup code on top.

This is the code when I click on numbers 121,2,72. it calls

{
														
data : "numbers",
	render : function(data,type, row) {
	var failureRespons=data.split("|");
	if(failureRespons[1]=='0')
      {   
      return failureRespons[1];
	  }
	else
	{
																														
	return '<a href="#" onclick="showFailureJobs('+failureRespons[0]+','+failureRespons[1]+')"  data-toggle="modal" data-target="#modalTable"><span class="text-primary">'+failureRespons[1]+'</span></a>'
																
	}															
}
}

Ajax call

	function showFailureJobs(jobId,jobCount)
	{

	  $.ajax({
			type : "GET",
			url : url bla bla,
			data : '',
			dataType : "json",
		    contentType: "application/json",
		    crossDomain:true,
			success : function(data) {	
			
				 $('#modalTable').on('shown', function() {
			 							
			 	 	$('#popupTable').bootstrapTable({
			 		    columns: [{
			 		            field: 'countryCode',
			 		            title: 'Country Code'
			 		        }, {
			 		            field: 'Number',
			 		            title: 'Number'
			 		        }, {
			 		            field: 'errorMessage',
			 		            title: 'Error Message'
			 		        }, {
			 		            field: 'jobId',
			 		            title: 'Job Id'
			 		        },{
			 		       
			 		            field: 'organizationName',
			 		            title: 'Organization Name'
			 		        }, 

			 		    ], 
			 		    
			 		data:data
			 		   
			 	 	});
			 	
				   })   
				   //Even I harcoded the data like this but I am not getting the data in table
					$(document).ready(function() {
				 	    $('#modalTable').on('shown', function() {
				 	        $('#popupTable').bootstrapTable({
				 	        data: [
							 	{
							 	  "countryCode" : "1",
							 	  "Number" : "NL",
							 	  "errorMessage" : "msg.",
							 	  "jobId" : "1",
							 	  "organizationName" : "us"
							 	},
							 	{
							 	  "countryCode" : "2",
							 	  "Number" : "NL",
							 	  "errorMessage" : "msg",
							 	  "jobId" : "10",
							 	  "organizationName" : "us"
							 	}
				 	        ]
				 	    });
				 	    })
				 	});
		

My json Data format

countryCode 		"NL"
Number 			    "4"
errorMessage 		"msg"
jobId 				"1"
organizationName 	"us"
update 1: html file content

<!DOCTYPE html>
<html lang="en">
	<title>
		Boostrap Modal Example
	</title>
	<head>
	<meta charset="utf-8">

		<script type="text/javascript" src="jquery.js"></script>
		<script type="text/javascript" src="bootstrap.js"></script>
		<link rel="stylesheet" type="text/css" href="bootstrap.css">

		<script type="text/javascript">
		  $(document).ready(function() {
            $('#modalTable').on('shown', function() {
                $('#table').bootstrapTable({
                  
			data: [
			 {
			  "Number" : "1",
			  "countryCode" : "NL",
			  "errorMessage" : "msg.",
			  "jobId" : "1",
			  "organizationName" : "us"
			},
			{
			  "Number" : "2",
			  "countryCode" : "NL",
			  "errorMessage" : "msg",
			  "jobId" : "10",
			  "organizationName" : "us"
			}
			        ]
    });
    })
});


		</script>

		<body>
    <!-- Button trigger modal -->
<button type="button" class="btn btn-primary btn-lg" data-toggle="modal" data-target="#modalTable">
  Launch demo modal
</button>

<div class="modal fade" id="modalTable" tabindex="-1" role="dialog" aria-labelledby="myModalLabel" aria-hidden="true">
    <div class="modal-dialog">
        <div class="modal-content">
            <div class="modal-header">
               
            </div>
            <div class="modal-body">
<table id="table">
    <thead>
     <tr>
     <th class="col-xs-1" data-field="jobId">Job ID</th>
     <th class="col-xs-1" data-field="Number"> Number</th>
     <th class="col-xs-2" data-field="organizationName">Organization Name</th>
     <th class="col-xs-1" data-field="countryCode">Country Code</th>
     <th class="col-xs-6" data-field="errorMessage"> Error Message</th>
     </tr>
   </thead>
</table>
    </div>
       <div class="modal-footer">
        <button type="button" class="btn btn-default" data-dismiss="modal">Close</button>
            </div>
        </div>
        <!-- /.modal-content -->
    </div>
    <!-- /.modal-dialog -->
</div>
<!-- /.modal -->

</body>

		
</html>

3
  • I tried to populate the json data into my model table. I dont know whats wrong. what is your question actually ? Commented Oct 9, 2015 at 10:36
  • I am not able to populate json data in bootstrap model table Commented Oct 9, 2015 at 10:40
  • BootstrapTable works in table not div . modalTable id belongs to div , not table. you didn't post or write the code for opening modal and didn't provide the code which calls the function showFailureJobs Commented Oct 9, 2015 at 10:45

1 Answer 1

2

Update: New version - http://jsfiddle.net/1dwy3zx9/4/


You can load a datato table when modal shown:

$(document).ready(function() {

    var tempModalParameters = {
        jobId: null,
        jobCount: 0
    };

    $('.show-modal').click(function() {
        tempModalParameters.jobId = $(this).attr('data-jobId');
        tempModalParameters.jobCount = $(this).attr('data-jobCount');

        $('#modalTable').modal('show');
    });

    $('#modalTable').on('shown', function() {        
        $('#table').bootstrapTable({
            data: getFakeDataWithParameter(tempModalParameters.jobId,  tempModalParameters.jobCount)
        });

        $('#table').bootstrapTable('hideLoading');
    });


    function getFakeDataWithParameter(jobId, jobCount){   
        return [{
                "Number": "1",
                "countryCode": "NL",
                "errorMessage": "msg.",
                "jobId": "1",
                "organizationName": "us"
            }, {
                "Number": "2",
                "countryCode": "NL",
                "errorMessage": "msg",
                "jobId": "10",
                "organizationName": "us"
            }];

    }
});

You html should be like this:

<!-- Button trigger modal -->
<ul>
    <li><a href="#" class="show-modal" data-jobId="1" data-jobCount="2">1</a>
    <li><a href="#" class="show-modal" data-jobId="2" data-jobCount="2">2</a>
    <li><a href="#" class="show-modal" data-jobId="3" data-jobCount="2">3</a>
</ul>

<div class="modal fade" id="modalTable" tabindex="-1" role="dialog" aria-labelledby="myModalLabel" aria-hidden="true">
    <div class="modal-dialog">
        <div class="modal-content">
            <div class="modal-header">

            </div>
            <div class="modal-body">

<table id="table">
    <thead>
                        <tr>
                            <th class="col-xs-1" data-field="jobId">Job ID</th>
                            <th class="col-xs-1" data-field="Number"> Number</th>
                            <th class="col-xs-2" data-field="organizationName">Organization Name</th>
                            <th class="col-xs-1" data-field="countryCode">Country Code</th>
                            <th class="col-xs-6" data-field="errorMessage"> Error Message</th>
                        </tr>
                    </thead>
</table>
            </div>
            <div class="modal-footer">
                <button type="button" class="btn btn-default" data-dismiss="modal">Close</button>
            </div>
        </div>
        <!-- /.modal-content -->
    </div>
    <!-- /.modal-dialog -->
</div>
<!-- /.modal -->

And you need import a javascript for jQuery, Bootstrap and BootstrapTable (http://wenzhixin.net.cn/p/bootstrap-table/docs/getting-started.html)

Sign up to request clarification or add additional context in comments.

13 Comments

I dont know Why My pop is not getting triggered ??
Firstly I think you must change $('#modalTable').bootstrapTable({ to $('#popupTable').bootstrapTable({
It's for you - working example - jsfiddle.net/1dwy3zx9/1 . You must load your data when show modal - $('#modalTable').on('shown', function() { // here load. In example you have this code
Hi bro I tried multiple way but dint work. as mentioned I tried in same way. now I am able to triggered the popup table but data is not populating.
jsfiddle.net/1dwy3zx9/1 Here is working example. Loda data after show modal - $(document).ready(function() { $('#modalTable').on('shown', function() { // here code to load data
|

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.