I am using DataTable to display the data. All the column names with check box is displaying when i click show and hide button. When i uncheck all the column and when i try to check the column name at that time the first column is getting copied or getting displayed in the all the row values.
Following is my code which i written.
$('#datatable_col_reorder').dataTable({
"processing": true,
"sAjaxSource": "<?php echo $config['ajaxUrlPath'];>json.php",
"bFilter" : true,
"fnServerData": function ( sAjaxSource , aoData, fnCallback ) {
aoData.push( { "name": "eventName", "value": $('#eventName').val() });
aoData.push( { "name": "et", "value": $('#Type').val() });
aoData.push( { "name": "vn", "value": $('#address').val() });
aoData.push( { "name": "da", "value": $('#date_added').val() });
aoData.push( { "name": "ti", "value": $('#time_added').val() });
aoData.push( { "name": "st", "value": $('#status').val() });
aoData.push( { "name": "br", "value": $('#status1').val() });
aoData.push( { "name": "cr", "value": $('#status2').val() });
aoData.push( { "name": "pr", "value": $('#spercentage').val() });
// etc
$( "#status2,#address,#spercentage" ).keyup(function() {
var table = $('#datatable_col_reorder').DataTable();
table.ajax.reload();
});
$( "#status,#Type,#date_added,#time_added,#status1,#status2" ).change(function() {
var table = $('#datatable_col_reorder').DataTable();
table.ajax.reload();
});
$.getJSON( sAjaxSource, aoData, function (json) { console.log(json); fnCallback(json) } );
},
"sDom":"<'col-sm-1 col-xs-1 col-md-1 col-lg-1 showHidebutton'C><'dt-toolbar'r>"+
"t"+
"<'dt-toolbar-footer'<'col-sm-6 col-xs-12 hidden-xs'i><'col-sm-6 col-xs-12'p>>",
"autoWidth" : true,
"rowCallback": function( nRow, aData, iDisplayIndex ) {
// responsiveHelper_datatable_tabletools.createExpandIcon(nRow);
$('td:eq(0)', nRow).html(''+aData[0]+'');
return nRow;
},
"preDrawCallback" : function() {
// Initialize the responsive datatables helper once.
if (!responsiveHelper_datatable_col_reorder) {
responsiveHelper_datatable_col_reorder = new ResponsiveDatatablesHelper($('#datatable_col_reorder'), breakpointDefinition);
}
},
"drawCallback" : function(oSettings) {
responsiveHelper_datatable_col_reorder.respond();
}
});
When i uncheck all and when i try to recheck each checkboxes, at that time the first column values are getting displayed in all other column like type,status,address etc.
Example: Consider Name: XYZ, After deselecting checkboxes if i try to recheck at that time the each column values is showing "XYZ" in status,address columns.
Thanks in advance.
Related
i have problem with duplicate position in datatables.
I have table with orders
id | order_no | status | etc.
and second table with order owners. Each order can have several owners.
In laravel controller i have code like this:
$orders = DB::table('orders')
->join('order_addresses', 'orders.id', '=', 'order_addresses.order_id')
->join('customers', 'orders.id_client', '=', 'customers.id')
->join('order_owners', 'orders.id', '=', 'order_owners.order_id')
'users.name as username', 'orders.comment', 'order_addresses.country')
->select('orders.id', 'orders.order_no', 'orders.deadline', 'customers.name as customersname', 'orders.comment', 'order_addresses.country')
->get();
return Datatables($orders)->make(true);```
and in view this
var url = "orders/show";
var table = $('#orders').DataTable({
"processing": true,
"serverSide": true,
"ajax": {
"dataType": "json",
"url": url,
"data": function(outData) {
// what is being sent to the server
console.log('i');
console.log(outData);
return outData;
},
dataFilter: function(inData) {
// what is being sent back from the server (if no error)
console.log('i2');
console.log(inData);
return inData;
},
error: function(err, status) {
// what error is seen(it could be either server side or client side.
console.log('i3');
console.log(err);
},
},
"columns": [{
sortable: false,
"render": function(data, type, full, meta) {
return '<span class="badge badge-danger"></span>';
}
},
{
"name": "id",
"data": ".id"
},
{
"name": "order_no",
"data": "order_no"
},
{
"name": "deadline",
"data": "deadline"
},
{
"name": "customersname",
"data": "customersname"
},
{
"name": "country",
"data": "country"
},
{
"name": "comment",
"data": "comment"
},
{
sortable: false,
"render": function(data, type, full, meta) {
var buttonID = full.id;
return 'edit';
}
},
],
});
When i add 2 owners in order i get duplicate datatables
So, how i can add in one column this 2 owners in one row?
my script as below. I have to search the pincode and based on search i have to show locations on map
Ques 1: if i have 2 results for same pincode, then also one marker is coming on the map. i want to show seperate markers.
Ques 2: i want to radar search as well using pincode. like if pincode 07201 and 07202 are very near areas then i should get results for both. i tried using radius in my response, but its not working
<script>
var map;
<!-- var marker; -->
function initialize()
{
var mapOptions = {
center: new google.maps.LatLng('40.71338', '-74.193246'),
zoom: 8,
scrollwheel: false,
disableDefaultUI: false,
mapTypeId: google.maps.MapTypeId.ROADMAP
};
map = new google.maps.Map(document.getElementById("map_canvas"),mapOptions);
marker = new google.maps.Marker({
position: new google.maps.LatLng(40.71338, -74.193246),
map: map,
});
}
jQuery('#searchPincodeForm').submit(function (event) {
event.preventDefault();
var geocoder = new google.maps.Geocoder();
var search_val=$('#country').val();
jQuery.ajax({
type: 'post',
data:{
'pincode':search_val,
},
url: 'searchPincode.php',
success:function(response){
if(response != ''){
$("#result").html(response).show();
geocoder.geocode({
'address': search_val }, function (results, status) {
if (status == google.maps.GeocoderStatus.OK) {
var position = results[0].geometry.location;
map.setCenter(position);
marker.setPosition(position);
}
})
} else{
$("#result").html("Sorry Dealer not available at this location. For more information please mail at info#movemaxoil.com").show();
}
}
});
});
</script>
Response i get from geocode:
{
"results": [{
"address_components": [{
"long_name": "07108",
"short_name": "07108",
"types": ["postal_code"]
},
{
"long_name": "Newark",
"short_name": "Newark",
"types": ["locality", "political"]
},
{
"long_name": "Essex County",
"short_name": "Essex County",
"types": ["administrative_area_level_2", "political"]
},
{
"long_name": "New Jersey",
"short_name": "NJ",
"types": ["administrative_area_level_1", "political"]
},
{
"long_name": "United States",
"short_name": "US",
"types": ["country", "political"]
}
],
"formatted_address": "Newark, NJ 07108, USA",
"geometry": {
"bounds": {
"northeast": {
"lat": 40.73179289999999,
"lng": -74.1830549
},
"southwest": {
"lat": 40.713114,
"lng": -74.21835
}
},
"location": {
"lat": 40.7235275,
"lng": -74.197388
},
"location_type": "APPROXIMATE",
"viewport": {
"northeast": {
"lat": 40.73179289999999,
"lng": -74.1830549
},
"southwest": {
"lat": 40.713114,
"lng": -74.21835
}
}
},
"place_id": "ChIJK0xWNjlTwokRLb_3zFLt8zM",
"types": ["postal_code"]
}],
"status": "OK"
}
So the issue is here:
var position = results[0].geometry.location;
map.setCenter(position);
marker.setPosition(position);
Your ajax response may contain more than one location point in it, but in the above code you are using only the first location point results[0].geometry.location here. So instead of results[0] you have to loop through all the results array so that multiple points are mapped on your mark.
when we pass static list of data like [{category":"a","data:"3"},"category":"b","data":"1"}]
then its working fine, but when we pass page url like {"url": "abc.php","format": "json"} in dataprovider section then chart not populate.
This is my code:
var chart = AmCharts.makeChart("chartdiv", {
"type": "pie",
"dataProvider":{ "
url": "abc.php",
"format": "json" },
"labelRadius": -35,
"labelText": "[[percents]]%",
"titleField": "category",
"valueField": "column-1",
"allLabels": [],
"balloon": {},
"legend": {
"enabled": true,
"align": "center",
"markerType": "circle" }
});
Any solution?
Using amCharts with "static" data
If you have "static" data, use the dataProvider setting, like this:
var chart = AmCharts.makeChart("chartdiv", {
"type": "pie",
"dataProvider": [{
"category": "a",
"data": 3
}, {
"category": "b",
"data": 1
}],
// ...
});
Using amCharts with AJAX data
If you want the data to be loaded using AJAX, one way is to make use of amCharts' Data Loader plugin.
Make sure to include it in your HTML:
<script src="amcharts/plugins/dataloader/dataloader.min.js" type="text/javascript"></script>
Leave out the dataProvider setting, and use dataLoader instead.
var chart = AmCharts.makeChart( "chartdiv", {
"type": "pie",
"dataLoader": {
"url": "abc.php",
"format": "json"
},
// ...
});
Your abc.php file should return valid JSON, like this:
[{
"category": "a",
"data": 3
}, {
"category": "b",
"data": 1
}]
You can find a complete list of options for the Data Loader plugin here: https://www.amcharts.com/kbase/using-data-loader-plugin/.
I have a PHP code that is being called by the function loader that is only triggered on onInitCreate event in datatable. What I want to do is that when the user clicks the add button it must load the faculty Names in the select field.
I've already tried this code but it returns nothing or should I say a null value. I'm confident that it should return exactly one row.
This is my PHP code that gets the faculty names and return it.
getFacultyNames.php
<?php
error_reporting(-1);
require_once("config.php");
$sql="SELECT lastName, firstName, middleName FROM table_faculty";
$result = mysql_query($sql);
$stack=array();
if($result === FALSE) {
die(mysql_error()); // TODO: better error handling
}
while($row = mysql_fetch_array($result))
{
$name = $row[0]." ,".$row[1]." ".$row[2];
array_push($stack,array("label" => $name, "value" => $name));
}
echo json_encode($stack); //here it returns [{"label":"Last ,First Middle","value":"Last ,First Middle"}]
?>
jquery code:
function loader(){
$.ajax({
"url": 'php/getFacultyNames.php',
"async": false,
"dataType": 'json',
"success": function (json) {
console.log( json );
//the getFacultyNames.php is now returning correct values,
//but how would I be able to get the value of the json code properly?
//it always throws an error ""parsererror" SyntaxError
//is it proper to have a code `return json;` in this success function?
},
"error" : function( jqXHR, textStatus, errorThrown ){ console.log( jqXHR, textStatus, errorThrown ); }
});
}
This is my editor initialization code:
var editor = new $.fn.dataTable.Editor( {
"ajaxUrl": "php/table.facultyloading.php",
"domTable": "#facultyloading",
"events": {
"onInitCreate":function (){
editor.add( {
"label": "Assign to Faculty",
"name": "facultyName",
"type": "select",
"ipOpts":loader() // Returns array of objects - .ajax() with async: false
});
}
},
"fields": [
{
"label": "Subject Name",
"name": "name",
"type": "select",
"ipOpts": [
{
"label": "sample",
"value": "sample"
}
]
},
{
"label": "Day",
"name": "day",
"default": "Monday",
"type": "checkbox",
"ipOpts": [
{
"label": "Monday ",
"value": "Monday "
},
{
"label": " Tuesday ",
"value": " Tuesday "
},
{
"label": " Wednesday ",
"value": " Wednesday "
},
{
"label": " Thursday ",
"value": " Thursday "
},
{
"label": " Friday ",
"value": " Friday "
},
{
"label": " Saturday",
"value": " Saturday"
}
],
"separator": "|"
},
{
"label": "Start Time",
"name": "startTime",
"type": "text"
},
{
"label": "End Time",
"name": "endTime",
"type": "text"
},
{
"label": "Room",
"name": "room",
"type": "text"
}
]
} );
I can't seem to figure out what is wrong.Am I missing something? Can you help me?
Thanks in advance!
I've converted the mysql function to PDO_MySQL and finally it works this is my new getFacultyNames.php and I've also modified my jquery code a bit. Thanks for all your help! :)
getFacultyNames.php
<?php
error_reporting(-1);
require_once("config.php");
$stack=array();
$stmt = $dbh->prepare("SELECT lastName, firstName, middleName FROM table_faculty");
if ($stmt->execute()) {
while ($row = $stmt->fetch(PDO::FETCH_ASSOC)) {
$name = $row['lastName']." ,".$row['firstName']." ".$row['middleName'];
array_push($stack,array($name,$name));
}
echo json_encode($stack);
}
?>
jquery code
function names(){
var test= new Array({"label" : "a", "value" : "a"});
test.splice(0,1);
$.ajax({
"url": 'php/getFacultyNames.php',
"async": false,
"dataType": 'json',
"success": function (json) {
for(var a=0;a < json.length;a++){
obj= { "label" : json[a][0], "value" : json[a][1]};
test.push(obj);
}
},
"error" : function( jqXHR, textStatus, errorThrown ){ console.log( jqXHR, textStatus, errorThrown ); }
});
return test;
}
Add die to end of getFacultyNames.php.
echo json_encode($stack);
die;
UPDATE
Try to remove "dataType": 'json' and set in callbaks:
try {
json = JSON.parse(data);
}
catch (e) {
console.log("Parse error:"+e);
};
use this
function loader(){
var responseText = $.ajax({
"url": 'php/getFacultyNames.php',
"async": false,
"dataType": null,
"error" : function( jqXHR, textStatus, errorThrown ){
console.log( jqXHR, textStatus, errorThrown );
}
}).responseText;
return $.parseJSON(responseText)
}
This will do the AJAX call and return you the properly formatted JSON object.
I am using the following code to enable live edit with jeditable:
<script type="text/javascript">
$(document).ready(function(){
var aDataSet = [
["klad1111.com","<img src='world/se.png' />","-","0","0","0%","0"],
["klad2222.com","<img src='world/dk.png' />","2012-12-05","1","3","300%","15"],
["klad33333.com","<img src='world/dk.png' />","-","0","0","0%","0"],
["klad6666.info","<img src='world/dk.png' />","-","0","0","0%","0"],
["klad44444.info","<img src='world/dk.png' />","-","0","0","0%","0"],
["klad5555.com","<img src='world/se.png' />","-","0","0","0%","0"],
];
$('#dynamic').html( '<table cellpadding="0" cellspacing="0" border="0" class="display" id="example"></table>' );
$('#example').dataTable( {
"aaData": aDataSet,
"aoColumns": [
{ "sTitle": "Namn" },
{ "sTitle": "Land" },
{ "sTitle": "Uppdaterad" },
{ "sTitle": "Neutrala Posts", "sClass": "center" },
{ "sTitle": "Post / Client", "sClass": "center" },
{ "sTitle": "Ratio", "sClass": "center" },
{ "sTitle": "Total Posts", "sClass": "center" }
]
} );
/* Init DataTables */
var oTable = $('#example').dataTable();
/* Apply the jEditable handlers to the table */
$('td', oTable.fnGetNodes()).editable( 'editable_ajax.php', {
"callback": function( sValue, y ) {
var aPos = oTable.fnGetPosition( this );
oTable.fnUpdate( sValue, aPos[0], aPos[1] );
},
"submitdata": function ( value, settings ) {
return {
"row_id": this.parentNode.getAttribute('id'),
"column": oTable.fnGetPosition( this )[2]
};
},
"height": "14px"
} );
});
</script>
Live edit kind of works, when i click on a cell i get up a input box. But the save part is not working.. I am not sure how to update my database accordingly..
Any ideas?