I've been trying to do this for several days, but hope someone could just have a better idea than me, I'm trying include an edit button to my Datatable but since I'm calling the data using the method in my Controller, I am not able to find a way to make this button work
Here is my Datatable method:
<link href="https://cdnjs.cloudflare.com/ajax/libs/toastr.js/latest/css/toastr.min.css" rel="stylesheet"/>
<link href="https://cdn.datatables.net/1.10.21/css/dataTables.jqueryui.min.css" rel="stylesheet" type="text/css">
<link href="https://cdn.datatables.net/scroller/2.0.2/css/scroller.jqueryui.min.css" rel="stylesheet" type="text/css">
<link href="https://cdn.datatables.net/buttons/1.6.2/css/buttons.dataTables.min.css" rel="stylesheet" type="text/css">
<script src="//code.jquery.com/jquery-1.12.3.js"></script>
<script
src="https://cdn.datatables.net/1.10.12/js/dataTables.bootstrap.min.js"></script>
<link rel="stylesheet"
href="//maxcdn.bootstrapcdn.com/bootstrap/3.3.6/css/bootstrap.min.css">
<link rel="stylesheet"
href="https://cdn.datatables.net/1.10.12/css/dataTables.bootstrap.min.css">
<script src="/js/jquery.min.js" ></script>
<script src="/js/jquery-ui.js" ></script>
<script src="https:////cdnjs.cloudflare.com/ajax/libs/toastr.js/latest/js/toastr.min.js"></script>
<script type="text/javascript" src="https://cdn.datatables.net/1.10.21/js/jquery.dataTables.min.js"></script>
<script type="text/javascript" src="https://cdn.datatables.net/1.10.21/js/dataTables.jqueryui.min.js"></script>
<script type="text/javascript" src="https://cdn.datatables.net/scroller/2.0.2/js/dataTables.scroller.min.js"></script>
<meta name="csrf-token" content="{{ csrf_token() }}">
<style type="text/css">
.loader {
position:fixed;
opacity: 0.5;
left: 0px;
top: 0px;
width: 100%;
height: 100%;
z-index: 9999;
background: url('/images/double_ring.gif') 50% 50% no-repeat rgb(249, 249, 249, 249);
}
.table tr:hover { background-color: #eeeeee;}
.content { background-color:white; }
</style>
<div id="loader" class="loader" style="display:none;"></div>
<h3 id='dashboard_title_header'>Pending Proposals</h3>
<br/>
</br>
<table id="table_roster" class="display nowrap">
<thead>
<tr>
<th>Proposal Number</th>
<th>Proposal Type</th>
<th>Sponsor Code</th>
<th>Prime Sponsor Code</th>
<th>Sponsor Assigned Proposal Number</th>
<th>Department Code</th>
<th>Status</th>
<th>Submission Deadline Date</th>
<th>Project Start Date</th>
<th>Proposal Specialist</th>
<th>PI</th>
</tr>
</thead>
</table>
<script type="text/javascript">
$.ajaxSetup({
headers: {
'X-CSRF-TOKEN': $('meta[name="csrf-token"]').attr('content')
}
});
function format ( d ) {
return '<table id="table_child" cellpadding="5" cellspacing="0" border="0" style="padding-left:50px;">'+
'<tr>'+
'<td>IRG:</td>'+
'<td>'+d[11]+'</td>'+
'<td>IRG Date:</td>'+
'<td>'+d[12]+'</td>'+
'<td>Council Cycle:</td>'+
'<td>'+d[13]+'</td>'+
'<td>Score:</td>'+
'<td>'+d[14]+'</td>'+
'<td>Percentile:</td>'+
'<td>'+d[15]+'</td>'+
'<td>Assessment:</td>'+
'<td>'+d[16]+'</td>'+
'<td>'+
'<button class="edit-model btn btn-info">'+
'<span class="glyphicon glyphicon-edit"></span>'+
'Edit'+
'</button>'+
'</td>'+
'</tr>'+
'</table>';
}
$(document).ready(function() {
var table = $('#table_roster').DataTable({
"processing": true,
ajax: "/getproposals",
//paging: true,
//pageLenght: '10',
deferRender: true,
scrollX: true,
scrollY: 400,
scrollCollapse: true,
scroller: true,
dom: 'Bfrtip',
"columnDefs": [
{
className: "dt-body-center",
targets: -1,
defaultContent: ["<i class='glyphicon glyphicon-edit text-info editButton' aria-hidden='true'></i>"]
}
]
});
$('#table_roster tbody').on('click', 'tr', function () {
var datas = table.row( this ).data();
var tr = $(this).closest('tr');
var row = table.row( tr );
if ( row.child.isShown() ) {
// This row is already open - close it
row.child.hide();
tr.removeClass('shown');
}
else {
// Open this row
row.child( format(row.data()) ).show();
tr.addClass('shown');
}
//EditProposal(data[0]);
});
$(document).on('click', '.edit-model', function() {
$('#footer_action_button').text(" Update");
$('#footer_action_button').addClass('glyphicon-check');
$('#footer_action_button').removeClass('glyphicon-trash');
$('.actionBtn').addClass('btn-success');
$('.actionBtn').removeClass('btn-danger');
$('.actionBtn').removeClass('delete');
$('.actionBtn').addClass('edit');
$('.modal-title').text('Edit');
$('.deleteContent').hide();
$('.form-horizontal').show();
var stuff = $(this).data('info').split(',');
fillmodalData(stuff)
$('#myModal').modal('show');
});
});
function EditProposal(id) {
window.open("/proposals/" + id);
}
</script>
And this is my method in the Controller
public function getProposals()
{
$sql = "SELECT proposal_number, proposal_type, sponsor_code, prime_sponsor_code, sponsor_assigned_proposal_number, award_admin_dept_code, status, submission_deadline_date, project_start_date, proposal_specialist, lname, IRG, IRGDate, CouncilCycleNumber, ScoreNumber, PercentageNumber, AssessmentEntry FROM proposal LEFT JOIN pendingproposals USING(proposal_id) LEFT JOIN proposal_research_team USING(proposal_id) WHERE proposal.status in ('Unsubmitted','Dept Approval In Process', 'Admin Office In Process', 'JIT Request Received', 'JIT Submitted', 'Submitted to Sponsor', 'Sub 1/4: Awaiting Agreement', 'Sub 2/4: Under Negotiation', 'Sub 3/4: Partially Executed') AND role = 'Lead Principal Investigator';";
$results = \DB::connection('mysql2')->select( \DB::raw($sql) );
$data = array();
$i = 0;
foreach ($results as $r) {
$data[$i] = array($r->proposal_number, $r->proposal_type, $r->sponsor_code, $r->prime_sponsor_code, $r->sponsor_assigned_proposal_number, $r->award_admin_dept_code, $r->status, $r->submission_deadline_date, $r->project_start_date, $r->proposal_specialist, $r->lname, $r->IRG, $r->IRGDate, $r->CouncilCycleNumber, $r->ScoreNumber, $r->PercentageNumber, $r->AssessmentEntry);
$i++;
}
$results2 = ["sEcho" => 1,
"iTotalRecords" => count($data),
"iTotalDisplayRecords" => count($data),
"aaData" => $data];
return json_encode($results2);
}
I appreciate your help :)
Related
content my controller :
<?php
defined('BASEPATH') OR exit('No direct script access allowed');
class AutoLoadDiv extends CI_Controller {
public function __construct()
{
parent::__construct();
}
public function index()
{
$this->load->view('ngoding/AutoLoad');
}
public function getData() {
$this->load->library('table');
$err = file_get_contents("application\logs\log.php");
$filestr = preg_replace(array('/(^|\R)ERROR\s*-\s*/', '/(^|\R)(.*?)\s*-->\s*/'), array('$1', '$1$2 '), $err);
$arraySpacing = nl2br($filestr);
$arr = explode("\n", $arraySpacing);
$output = '<style> th, td {text-align: left; padding: 10px;} tr:nth-child(even){background-color#FFF;} tr:nth-child(odd){background-color:#CCC;} </style>';
$output .= '<table border="1px solid #dddddd;" >';
$output .= '<tr><th>Date</th><tr>';
for ($i = count($arr)-1; $i >= 0; $i--) {
$output.="<tr><td>$arr[$i]</td></tr>";
}
$output.="</table>";
echo $output;
}
}
Here code view after try to implementing Datatables but not working
<html>
<head>
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.6/css/bootstrap.min.css">
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<link rel="stylesheet" type="text/css" href="https://cdn.datatables.net/1.10.19/css/jquery.dataTables.css">
<script type="text/javascript" charset="utf8" src="https://cdn.datatables.net/1.10.19/js/jquery.dataTables.js">
<script>
$(document).ready(function(){
setInterval(function(){
$("#table").load('AutoLoadDiv/getData')
}, 5000);
});
</script>
<style>
</style>
<title>Auto Load Page in Div using Jquery</title>
</head>
<body>
<h1>Auto Load Page in Div</h1>
<div id="content">Please wait....</div>
<div class="container">
<table id="table" class="display" cellspacing="0" width="100%">
<tr>
<th>Date</th>
</tr>
</table>
</div>
<script type="text/javascript">
var table;
table = $(document).ready(function() {
//datatables
table = $('#table').DataTable({
"processing": true,
"serverSide": true,
"order": [],
"ajax": {
"url": "<?php echo site_url('AutoLoadDiv/getData')?>",
"type": "POST"
},
"columnDefs": [
{
"targets": [ 0 ],
"orderable": false,
},
],
});
});
</script>
</body>
</html>
After I implementing Datatables, result view like this :
https://ibb.co/keTQYe
I have problem to implementing my code to make menu like dropdown to ascending and descending like this example : https://ibb.co/chO2Bz, I want to implamenting html asc and dsc in controller, not in view ,if I click that menu is sort to ascending , if click that menu again is sort to descending?
When we update the records in database its updated perfectly and not reflected in datatables. When we refresh the page datatables are updated.I need with out refresh the page datatables are updated.please help me.
<?php
define('DB_SERVER', 'localhost'); // Your Database host
define('DB_USERNAME', 'root'); // Your Database user name
define('DB_PASSWORD', 'root'); // Your Database password
define('DB_DATABASE', 'qwer'); // Your Database Name
$connection = mysqli_connect(DB_SERVER,DB_USERNAME,DB_PASSWORD,DB_DATABASE); // Connection
$sql = "SELECT nickname, email ,created_date_time,real_chips FROM users ";
$rs = mysqli_query($connection,$sql);
$str ="";
$data = array();
while ($row = mysqli_fetch_assoc($rs))
{
$str .= '<tr id="dialog-confirm">';
$str .= '<td>'.$row["nickname"].' </td> <td>'. $row["email"].'</td><td>'. $row["created_date_time"].'</td><td>'. $row["real_chips"].'</td>';
$str .= '</tr>';
}
?>
<!DOCTYPE html>
<html>
<head>
<meta http-equiv="content-type" content="text/html; charset=UTF-8">
<title>Admin demo</title>
<style type="text/css" title="currentStyle">
#import "demo_page.css";
#import "demo_table.css";
</style>
<script type='text/javascript' src='http://code.jquery.com/jquery-1.9.1.js'></script>
<script type="text/javascript" src="http://code.jquery.com/ui/1.9.2/jquery-ui.js"></script>
<link rel="stylesheet" type="text/css" href="http://code.jquery.com/ui/1.9.2/themes/base/jquery-ui.css">
<!--<link rel="stylesheet" type="text/css" href="/css/result-light.css"> -->
<script type='text/javascript' src="http://cdn.datatables.net/1.10.2/js/jquery.dataTables.min.js"></script>
<link rel="stylesheet" type="text/css" href="http://cdn.datatables.net/1.10.2/css/jquery.dataTables.min.css">
<script type='text/javascript' src="http://jquery-datatables-column-filter.googlecode.com/svn/trunk/media/js/jquery.dataTables.columnFilter.js"></script>
<script src="http://code.jquery.com/jquery-migrate-1.1.0.js"></script>
<script type='text/javascript'>//<![CDATA[
$(window).load(function(){
$(document).ready(function () {
$.datepicker.regional[""].dateFormat = 'yy-mm-dd';
$.datepicker.setDefaults($.datepicker.regional['']);
drawDataTable = function()
{
$('#example').dataTable({
"aoColumns": [{
"sWidth": "200px"
},
null,
null,
null]
})
.columnFilter({
sPlaceHolder: "head:before",
aoColumns: [{
type: "text"
}, {
type: "text"
}, {
type: "date-range"
},{
type: "text"
}]
});
}
// call datatable for the first time when page loads
drawDataTable();
$('#example').on("click", "tr#dialog-confirm", function () {
var tableData = $(this).children("td").map(function () {
return $(this).text();
}).get();
//' + $.trim(tableData[0]) + '
var dynamicDialog = $('<div id="MyDialog" > <div><div style="width:150px;float:left;">Amount</div><div style="float:left;">:</div><div style="width:150px;float:left;"><input type="text" name="amount" id="amount" style="width:150px;"/><input type="text" name="nickname" id="nickname" value="'+$.trim(tableData[0])+'" style="display:none;"/></div></div><div><div style="width:150px;float:left;">Password</div><div style="float:left;">:</div><div style="width:150px;float:left;"><input type="password" name="password" id="password" style="width:150px;"/></div></div></div>');
dynamicDialog.dialog({
title: "Admin chips adding",
modal: true,
height: 250,
width: 400,
buttons: [{
text: "Yes",
click: function ()
{
$.ajax({
type: "POST",
dataType: "html",
url: "Chips_AddedByAdmin.php",
cache: false,
data: {
username: $.trim(tableData[0]),
amount: $('#amount').val(),
password: $('#password').val()
},
beforeSend: function () {
$('#MyDialog').html('loading please wait...');
},
success: function (htmldata) {
//destroy existing datatable
$('#example').dataTable().fnDestroy();
//call datatable
drawDataTable();
$('#MyDialog').html("You have successfully updated the database");
dynamicDialog.dialog("close");
}
});
}
}, {
text: "No",
click: function (e) {
$(this).dialog("close");
}
}]
});
});
});
});//]]>
</script>
</head>
<body>
<table id="example" class="display">
<thead>
<tr>
<th style="width: 150px;">UserName</th>
<th style="width: 150px;">Email</th>
<th style="width: 180px;">Created Date</th>
<th style="width: 180px;">Real Chips</th>
</tr>
<tr>
<th style="width: 150px;">UserName</th>
<th style="width: 150px;">Email</th>
<th style="width: 180px;">Created Date</th>
<th style="width: 180px;">Real Chips</th>
</tr>
</thead>
<tbody>
<?php
echo $str;
?>
</tbody>
</table>
</body>
</html>
And ajax dataupdate php is here
<?php
require_once("configure.php");
echo $nickname = $_POST['username'];
echo $amount = $_POST['amount'];
echo $password = $_POST['password'];
echo $sql = "SELECT * FROM users WHERE nickname ='admin' and password='$password';";
$rs = mysqli_query($connection,$sql);
$numrows=mysqli_num_rows($rs);
if($numrows > 0)
{
echo $sql = "update users set real_chips=real_chips+'$amount' where nickname='$nickname';";
$rs = mysqli_query($connection,$sql);
}
?>
Not sure what you have going on here, but this is completely different than how I would do it.
Lets say I had a datatable defined like this:
oTable = $("table").dataTable({ ... settings ... });
If I ever wanted to refresh that datatable, all I would ever have to call is:
oTable.fnDraw();
That's it.
Destroying, building extra functions, etc. is not needed like in your code. It's all right there for you when you open the doc's up.
I was redirecting to new page start.php and passing variable in this way:
window.location.href = 'start.php?&userid=+ userid;`
Can I do it in this way:
$.post('start.php',{userid: userid});
window.location.href = 'start.php';
I dont want to use GET and Form submit.
Because on same page there are other processes which already post data to other page.
I tested above but on start.php it says var is not defined
UPDATE
start.php
<?php
$user_id=$_GET['userid']; //When I use GET
?>
<?php
$user_id=$_POST['userid']; //When I use POST
?>
login.php
<html>
<head>
<title>ThenWat</title>
<link href="css/button.css" rel="stylesheet" type="text/css">
<link href="css/rateit.css" rel="stylesheet" type="text/css">
<script src="//connect.facebook.net/en_US/all.js"></script>
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.8.2/jquery.min.js"></script>
<script src="js/jquery.rateit.js" type="text/javascript"></script>
<style>
.header{
background-color:#0B6121;
border:2px solid #0B6121;
padding:10px 40px;
border-radius:5px;
}
.middle{
background-color:Yellow;
}
.left{
background-color:Green;
}
.url{
box-sizing: border-box;
display: block;
}
.url:hover {
box-shadow: 2px 2px 5px rgba(0,0,0,.2);
}
html, body { margin: 0; padding: 0; border: 0 }
</style>
</head>
<body>
<div class="header" style="">
<table style="">
<tr>
<td><img src= "3.png" height="50" width="310"/></td>
</tr>
</table>
</div>
<table border="0" width="100%">
<tr>
<div class="middle">
<td style="width:40%">
<input type="button" id="loginButton" class="button" onclick="authUser();" value="Login | ThanWat" style="display:none; left:500px; position:relative"/>
<lable id="lable1" style="display:none;" ><i> Please wait .. </i> </lable>
<div class="rateit bigstars" id="rateit99" data-rateit-starwidth="32" data-rateit-starheight="32" style=" position:relative; top:-30px; display:none; left:300px" >
</div>
</td>
</div>
</tr>
</table>
<div id="fb-root"></div>
<script type="text/javascript">
var userid;
FB.init({
appId: '1412066',
xfbml: true,
status: true,
cookie: true,
});
FB.getLoginStatus(checkLoginStatus);
function authUser()
{
FB.login(checkLoginStatus, {scope:'email'});
}
function checkLoginStatus(response)
{
document.getElementById('lable1').style.display = 'block';
if(response && response.status == 'connected')
{
FB.api('/me?fields=movies,email,name', function(mydata)
{
console.log(mydata.email);
console.log(mydata.id);
userid=mydata.id;
var name=mydata.name;
//alert(name);
var email=mydata.email;
var json = JSON.stringify(mydata.movies.data);
var a = JSON.parse(json);
var picture="https://graph.facebook.com/"+userid+"/picture?type=small";
// alert(picture);
$.post('user_record.php',{'myd':a, name: name, email: email, userid:userid, picture:picture}, function(data)
{
window.location.href = 'start.php?userid='+userid;
});
});
console.log('Access Token: ' + response.authResponse.accessToken);
}
else
{
document.getElementById('lable1').style.display = 'none';
document.getElementById('loginButton').style.display = 'block';
}
}
</script>
</body>
</html>
UPDATE2
$.post('user_record.php',{'myd':a, name: name, email: email, userid:userid, picture:picture}, function(data)
{
var $form = $("<form id='form1' method='post' action='start.php'></form>");
form.append('<input type="hidden" name="userid" value="'+userid+'" />');
$('body').append($form);
window.form1.submit();
});
start.php
<?php
$user_id=$_POST['userid'];
echo $user_id;
?>
Here is a solution that worked for me. You need to add a new form using jquery after your first ajax response and then submit this form using javascript.
<script>
$.post('user_record.php',{'myd':a, name: name, email: email, userid:userid, picture:picture}, function(data){
var $form = $("<form id='form1' method='post' action='start.php'></form>");
$form.append('<input type="hidden" name="userid" value="'+data+'" />');
$('body').append($form);
window.form1.submit();
});
</script>
Please modify it according to your requirement. Hope this helps
I'm making a table, using the jQuery library (DataTables), and wanted to add buttons to export the results of the table to an Excel file, then lead me by the example that this page, and get them exported, but I now send an alert when the page loads, I've been reading on the internet and say it manages modifying some lines and states within the scripts, but I could not fix it,when i open the page, it showme the next error:
DataTables warning (table id = 'example'): Cannot reinitialise DataTable.
To retrieve the DataTables object for this table, pass no arguments or
see the docs for bRetrieve and bDestroy
I call my scripts by the next form:
index.php
<meta charset="utf-8">
<script src="js/jquery.js" type="text/javascript"></script>
<script src="js/funciones.js" type="text/javascript"></script>
<script src="js/jquery.dataTables.js" type="text/javascript"></script>
<link href="css/cuerpo.css" rel="stylesheet" type="text/css" />
<!--Prueba-->
<style type="text/css" title="currentStyle">
#import "css/demo_page.css";
#import "css/TableTools.css";
</style>
<script src="js/TableTools.js" type="text/javascript"></script>
<script src="js/ZeroClipboard.js" type="text/javascript"></script>
<script type="text/javascript" charset="utf-8">
$(document).ready( function () {
$('#example').dataTable( {
"sDom": 'T<"clear">lfrtip'
} );
} );
</script>
<!--Prueba-->
</head>
<body id="dt_example">
<div id="container">
<div id="header">
</div>
<div id="intro">
<header id="titulo">
</header>
<div id="demo">
<article id="contenido"></article>
<br><br>
</div>
</div>
</body>
and it call a JS page:
$(document).ready(function(){
verlistado()
//se carga la lista de la consulta
})
function verlistado(){ //funcion para mostrar el listado en el index por jquery
var randomnumber=Math.random()*11;
$.post("Registro/lista_base.php", {
randomnumber:randomnumber
}, function(data){
$("#contenido").html(data);
});
}
after it use the jQuery library and print on a php data table:
$(document).ready(function(){
$('#example').dataTable( { //convertimos nuestro listado de la forma del jquery.datatables- pasamos el id de la tabla
"sPaginationType": "full_numbers" //damos formato a la paginacion(numeros)
} );
})
<!--Prueba-->
<style type="text/css" title="currentStyle">
#import "css/TableTools.css";
</style>
<script src="js/TableTools.js" type="text/javascript"></script>
<script src="js/ZeroClipboard.js" type="text/javascript"></script>
<script type="text/javascript" charset="utf-8">
$(document).ready( function () {
$('#example').dataTable( {
"sDom": 'T<"clear">lfrtip'
} );
} );
</script>
<!--Prueba-->
<script language="JavaScript" type="text/javascript">
function PopWindow(idUsuario)
{
window.open('Registro/detalle.php?id='+idUsuario,'Registo del alumno','width=420, height=350');
}
</script>
<script type="text/javascript" language="javascript" src="js/listado.js"></script>
<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.3.2/jquery.js"></script>
<script>
$(document).ready(function()
{
$('[rel=tooltip]').bind('mouseover', function()
{
if ($(this).hasClass('ajax'))
{
var ajax = $(this).attr('ajax');
$.get(ajax,
function(theMessage)
{
$('<div class="tooltip">' + theMessage + '</div>').appendTo('body').fadeIn('fast');});
}
else{
var theMessage = $(this).attr('content');
$('<div class="tooltip">' + theMessage + '</div>').appendTo('body').fadeIn('fast');
}
$(this).bind('mousemove', function(e)
{
$('div.tooltip').css
({
'top': e.pageY - ($('div.tooltip').height() / 2) - 5,
'left': e.pageX + 15
});
});
}).bind('mouseout', function(){
$('div.tooltip').fadeOut('fast', function(){
$(this).remove();
});
});
});
</script>
<style>
.tooltip
{
position:absolute;
width:250px;
background-image:url(images/tip-bg.png);
background-position:left center;
background-repeat:no-repeat;
color:#FFF;
padding:5px 5px 5px 18px;
font: Verdana, Geneva, sans-serif;
font-size:12px;
}
li
{
margin-bottom:30px;
}
#wrapper
{
margin:0 auto;
width:500px;
margin-top: 99px;
}
</style>
<div id="demo">
<table cellpadding="0" cellspacing="0" border="0" class="display" id="example">
<thead>
<tr>
<th>Instituto</th>
<th>Categoria</th>
<th>Version</th>
<th width="20%">Nombre</th>
<th>Nacionalidad</th>
<th>email</th>
<th>Puntaje</th>
<th>Comprobante</th>
<th width='1%'>Detalles</th>
</tr>
</thead>
<tfoot>
<tr>
</tr>
</tfoot>
<tbody>
<?php
while($reg= mysql_fetch_array($listado))
{
echo '<tr>';
echo '<td><center>'.mb_convert_encoding($reg['razon_comercial'], "UTF-8").'</center></td>';
echo '<td><center>'.mb_convert_encoding($reg['categoria'], "UTF-8").'</center></td>';
echo '<td><center>'.mb_convert_encoding($reg['version'], "UTF-8").'</center></td>';
echo '<td>'.mb_convert_encoding($reg['Nombre'], "UTF-8").'</td>';
echo '<td><center>'.mb_convert_encoding($reg['nacionalidad'], "UTF-8").'</center></td>';
echo '<td>'.mb_convert_encoding($reg['email'], "UTF-8").'</td>';
echo '<td><center>'.mb_convert_encoding($reg['calificacion'], "UTF-8").'</center></td>';
echo "<td><center><a href='".mb_convert_encoding($reg['comprobante'], 'UTF-8')."'</a>descargar</center></td>";
echo "<td><a href=javascript:PopWindow(".mb_convert_encoding($reg['idAlumno'], 'UTF-8').") alt=Image Tooltip rel=tooltip content='
<div id=con><b>Nombre: </b>".mb_convert_encoding($reg['Nombre'], "UTF-8")."<br>
<b>Nacionalidad: </b>".mb_convert_encoding($reg['nacionalidad'], "UTF-8")."<br>
<b>Correo: </b>".mb_convert_encoding($reg['email'], "UTF-8")."<br>
<b>Instituto: </b>".mb_convert_encoding($reg['razon_comercial'], "UTF-8")."<br>
<b>Puntaje: </b>".mb_convert_encoding($reg['calificacion'], "UTF-8")."<br>
<b>Categoria: </b>".mb_convert_encoding($reg['categoria'], "UTF-8")."<br>
<b>VersiĆ³n: </b>".mb_convert_encoding($reg['version'], "UTF-8")."</div>'><center><img src='images/detail.png' width='20%'></center></a><br></td>";
echo '</tr>';
}
?>
</tbody>
</table>
I hope you can help me.
I think the problem you're having is that the javascript is firing before the data is loaded. To get around this make sure the script is located BELOW the table that is being populated.
You are calling a dataTable against #example twice on the same page which will throw the "DataTables warning (table id = 'example'): Cannot reinitialise DataTable" error
Previous answer is correct, but, if you want to add the export buttons, you also need the flash path.
sSwfPath: "/swf/copy_csv_xls_pdf.swf",
I'm using jQuery data table in my site. I have integrated the "Multi-tab" functionality and "Ajax Content loading" functionality with the datatables. Now I want to integrate the search option in my data table. My coding is:
$(document).ready(function() {
$("#tabs").tabs({ // My datatable Div Id
"show": function(event, ui) {
var oTable = $('div.dataTables_scrollBody>table.display', ui.panel).dataTable();
if ( oTable.length > 0 ) {
oTable.fnAdjustColumnSizing();
}
}
});
$('#example1').dataTable({ //example1->My first table Id
"bProcessing": true,
"sAjaxSource": "test_data.php", // "test_data.php" provides content for my first table
"bJQueryUI": true,
"sPaginationType": "full_numbers"
});
$('#example2').dataTable({ // example2->My second table Id
"bProcessing": true,
"sAjaxSource": "test_data2.php", // "test_data2.php" provides content for my second table
"bJQueryUI": true,
"sPaginationType": "full_numbers"
});
});
I found in the "Examples of Data table" for the solution of searching option. That coding is:
var asInitVals = new Array();
$(document).ready(function() {
var oTable = $('#example').dataTable( {
"oLanguage": {
"sSearch": "Search all columns:"
}
});
$("tfoot input").keyup( function () {
/* Filter on the column (the index) of this element */
oTable.fnFilter( this.value, $("tfoot input").index(this) );
});
/*
* Support functions to provide a little bit of 'user friendlyness' to the textboxes in
* the footer
*/
$("tfoot input").each( function (i) {
asInitVals[i] = this.value;
});
$("tfoot input").focus( function () {
if ( this.className == "search_init" )
{
this.className = "";
this.value = "";
}
});
$("tfoot input").blur( function (i) {
if ( this.value == "" )
{
this.className = "search_init";
this.value = asInitVals[$("tfoot input").index(this)];
}
});
});
Please guide me to integrate the above solution in my code otherwise please give your suggestion to integrate the search option.
This Example Code may helps you...
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
<html>
<head>
<meta http-equiv="content-type" content="text/html; charset=utf-8" />
<title>Working on Datatable</title>
<!-- Your JQuery Library -->
<script type="text/javascript" language="javascript" src="jquery-1.6.1.min.js"></script>
<!-- Your DataTable library -->
<script type="text/javascript" language="javascript" src="jquery.dataTables.js"></script>
<script type="text/javascript" charset="utf-8">
$(document).ready(function()
{
$('#userlist').dataTable({
"sDom": '<"toolbar">frtip'
});
} );
</script>
</head>
<body>
<div class="box">
<div style="width:100%;">
<table cellpadding="0" cellspacing="0" id="userlist" width="100%" style="border: 1px solid #0000CC; margin-top:10px;margin-bottom:10px;">
<thead>
<tr style=" background-color:#004677; font-size:14px; color:#fff; font-weight:bold;" height="30">
<th>Slno</th>
<th>User ID</th>
<th>Name</th>
<th>Email</th>
<th>City</th>
<th>Contact Number</th>
</tr>
</thead>
<tbody>
<tr>
<td>1</td>
<td>0001</td>
<td>Hearaman</td>
<td>hearaman.dev#gmail.com</td>
<td>Bangalore,India</td>
<td>9740798429</td>
</tr>
<tr>
<td>2</td>
<td>0002</td>
<td>Raman</td>
<td>raman#gmail.com</td>
<td>Hyderabad,India</td>
<td>886798429</td>
</tr>
<tr>
<td>3</td>
<td>0003</td>
<td>Satish Chandra</td>
<td>satishchandra.surampudi#gmail.com</td>
<td>Bangalore,India</td>
<td>948209876</td>
</tr>
<tr>
<td>4</td>
<td>0004</td>
<td>satish</td>
<td>satish#gmail.com</td>
<td>Bangalore,India</td>
<td>987639029</td>
</tr>
</tbody>
</table>
</div>
</div>
</body>
</html>
To Download DataTable plug-in and to see more examples, Visit http://datatables.net/
Ok as far as i get it. Add filter option searching i.e.
$(document).ready(function() {
$('#example1').dataTable({ //example1->My first table Id
"bProcessing": true,
"searching" : true,
"sAjaxSource": "test_data.php", // "test_data.php" provides content for my first table
"bJQueryUI": true,
"sPaginationType": "full_numbers"
});
$('#example2').dataTable({ // example2->My second table Id
"bProcessing": true,
"searching": true,
"sAjaxSource": "test_data2.php", // "test_data2.php" provides content for my second table
"bJQueryUI": true,
"sPaginationType": "full_numbers"
});
});