I have a grid that has the first two left hand columns as fixed. I would also like to prevent Button/colVis from allowing those two columns to be hidden. Is this possible?
Preventing some columns from being hidden?
Editing Dilemma of columns not in the datatable being viewed.
For example I am showing a datatable of user purchases. When I click on the user account I would like to open up the user profile and edit it.
Something like https://editor.datatables.net/examples/advanced/formOnlyData.html but the form data should come from another source.
Any ideas?
Thanks!
Excel Export: Adding background color to a cell if meets a condition
Hello! How would I go about adding a background color using the customize function to add a background color if the cell in the table meets the requirements? For example, a column called **replay **has values of "Approved", "Overturned", and "Check Supervisor". Approved => Green, Overturned => Yellow, Check Supervisor => Blue.
Server-side processing, empty JSON
Hi,
For a first try I would like to display only the ids of a table in a Datatable by using Serverside processing. But I'm searching for a few days and I can't success. I get a 'invalid json response' What's wrong with that :
<!DOCTYPE html>
<html>
<head>
<script type="text/javascript">
var table;
$(document).ready(function() {
table = $('#table').DataTable({
"processing": true,
"serverSide": true,
"ajax": {
"url": "application/php/joinArray.php",
"type": "POST"
} ,
"columns": [
{ "data": "id" }]
});
});
</script>
</head>
<body>
<div class="container">
<table id="table" class="table table-striped table-bordered" cellspacing="0" width="100%">
<thead>
<tr>
<th>Id</th>
</tr>
</thead>
<tfoot>
<tr>
<th>Id</th>
</tr>
</tfoot>
</table>
</div>
</body>
</html>```
Server side phpscript :
<?php
include('../libraries/Editor-PHP-1.6.1/php/DataTables.php');
use
DataTables\Editor,
DataTables\Editor\Field,
Editor::inst( $db, 'interventions' )->fields(Field::inst('id'))->process($_POST)->json();
`
Merge column data with nested arrays
Hi, I'm trying to merge two columns. Each has a nested array, which makes "clean" data loading complicated. Here's the function I'm using for rendering:
( data, type, full ) => {
return $.map( data, function ( d, i ) {
return d.given +' '+ d.family;
} ).join( ',<br />' );
}
I also have a JSFiddle online with a working example. As you can see, on the third column, the suggest method for the merge doesn't work. In any case, I would prefer rendering a column with data from both arrays, preferably in the same function, but I cannot see to access them using "full[]arrayname" nor "data[]arrayname".
IOS devices notworking
I'm using Laravel and Datatable with Yajra. Fetching the data server-side.
The code is working on windows and android devices but not on IOS devices.
var table_all = $('#loans-table-all').DataTable({
processing: true,
serverSide: true,
iDisplayLength: 100,
ajax: location.protocol+'/active-loans-ajax-all',
"columnDefs": [
{ className: "text-right", "targets": [ 5,6,7,8,9,10,11,12 ] },
{ className: "text-center", "targets": [ 1 ] }
],
columns: [
{data: 'loan_acct_no', name: 'loan_acct_no'},
{data: 'option', sortable:false},
{data: 'lname',name:'lname', visible: false},
{data: 'fname',name:'fname', visible: false},
{data: 'mname',name:'mname', visible: false},
{data: 'complete_name',name:'lname'},
{data: 'branch_name', name: 'branch_name'},
{data: 'area_name',name:'area_name'},
{data: 'loan_amount', name: 'loan_amount'},
{data: 'total_payable', name: 'total_payable'},
{data: 'daily', searchable:false},
{data: 'rem_balance', name: 'rem_balance'},
{data: 'date_due',name: 'date_due'}
]
});
How to set columns with different widths.
I am using datatable with server side processing.I want columns with different width based on the datatype
Excel like navigation - inline datepicker field does not work
In excel like navigation inline datepicker is not setting the date (not working in examples also) properly.
Help!!
selectbox not working in standalone mode, but ok in normal, bubble and inline mode
He guys,
I'm running into some unexpected behaviour. I'm using a mjoin for population a one to many dropdown. I'm using selectize but also tried chosen and select2. When i do so, it works great in the edit popup, bubble and inline. But when I use the same field inline the select boxes aren't populated. Since the server side and js is the same , i'm wondering if there might be some initialisation script not being triggered by the stand alone version. the only other option i can think of it that i'm doing something wrong in the way i use the data-editor-field but if i change it the selectbox isn't loaded at all so it seems to be ok...
What i've done is the following:
php:
->join(
Mjoin::inst('projects', 'array')
->link('costs.id', 'costs_projects.costs_id')
->link('projects.id', 'costs_projects.projects_id')
->fields(
Field::inst('id')
->validator( 'Validate::required' )
->options( 'projects', 'id', array('id','product','title') ),
Field::inst('product'),
Field::inst('title')
)
)
js field declaration:
fields: [
{ "label": "projects:", "name": "projects[].id", "type": "selectize", "attr": { multiple: "true", size: "4" } },
html for the standalone page:
<dd class="canedit" data-editor-field="projects[].id">-</dd>
Any help would be very much appreciated!
thanks,
wouter
Track Record of Trivandrum Builders
Builders in Trivandrum are leading construction companies with an enviable track record and they have been providing high quality construction services since their inception. Every flat or apartment created by builders in Trivandrum have stood the test of time and many of their projects are based in locations like Thycaud, Pulimoodu and Akkulam. They feature elegantly designed homes that harness what the nature has to offer incredibly. Builders in Trivandrum offer a unique facility at prime locations with convenient access from front and back end. Moving into a residential facility built by Trivandrum builders will be a wise investment decision. Common amenities offered in a Trivandrum villa include roof top swimming pool, roof top party area, fitness centre, children’s play area, and conference hall.
Builders in Trivandrum take their flat occupants to the next level of apartment living and unique facilities offered at Trivandrum flats enhance life. They provide easy access to amenities including educational institutions, banks, showrooms and the excitement of city life offered at Trivandrum flats attract many. Flat occupants can get the feel of serene residential area by staying in a Trivandrum based apartment. Trivandrum flat is considered as an elegant place to live in and a safe investment opportunity. People at the helm of builders in Trivandrum recognize that the pursuit of happiness begins at home. Clear vision, dedicated team and on time project delivery are the principal features of Trivandrum based builders. Highly successful projects conceptualized by Trivandrum builders helped them to hit the headlines of local dailies. Builders in Trivandrum define home as an area blended with quality, serenity, affordability as well as prosperity.
Using standalone editor, select/select2 is not populated with data
Dear Allan,
I am trying to build a standalone editor, in which i only have an html button to add new record.
The only problem is, when editor window opens, select2 (or select) is not populated with data.
I think ajax must be loaded in the initiliaziton of the page.
You can find the code below;
Is there a way to fix this problem?
var companies_editor = new $.fn.dataTable.Editor( {
ajax: {
url: 'classes/test_crud.php',
error: function(xhr, textStatus, errorThrown) { console.log('Error : ',errorThrown); }// Handle error
},
fields: [
{label: "Şirket İsmi:", name: "companies.name"},
{label: "Tipi:", name: "companies.type", type: "select2"},
{label: "Tel1:", name: "companies.tel1"},
{label: "Tel2:", name: "companies.tel2"},
{label: "Gsm:", name: "companies.gsm"},
{label: "Faks:", name: "companies.fax"},
{label: "Email 1:", name: "companies.email1"},
{label: "Email 2:", name: "companies.email2"},
{label: "Web Sitesi:", name: "companies.website"},
{label: "Adres:", name: "companies.address"},
{label: "Semt:", name: "companies.area"},
{label: "İlçe:", name: "companies.district"},
{label: "Posta Kodu:", name: "companies.zip"},
{label: "Şehir:", name: "companies.city"},
{label: "Ülke:", name: "companies.country", def:"Türkiye"},
{label: "Vergi Dairesi:", name: "companies.taxoffice"},
{label: "Vergi Numarası:", name: "companies.taxid"},
{ label: "Not:", name: "companies.note", type:"textarea"}
]
} );
$('#edit').on( 'click', function () {
companies_editor
.buttons( {
label: "Save",
fn: function () { this.submit(); }
} )
.create();
} );
Edited by Allan - Syntax highlighting. Details on how to highlight code using markdown can be found in this guide.
Pass additional meta-data to columns configuration
Hi,
referring to this post, is there any way to add some custom additional data (I specifically need to add relationships and aliases to table fields) to every column in datatable configuration?
Thank you,
Alex
Where's gone the records quantity selector?
Hi, everyone. In the examples in datatables site, qhen you use the editor buttons (New, Edit, Delete) the selector for number of records is missed, so I can't choose to see 10, 15, 25...etc records. No example in the site shows the edit buttons together to number of records selector. Can they both appear on the page simoultanously?
Thanks, Allan.
File Upload content stored in the same database table?
Are there some example(s) of File Upload storing the actual file content (in a MEDIUMBLOB) plus MIME type etc in the same database table? 1
I tried the following, but it did not work well:
Field::inst( 'sh_fileName' )
->upload(
Upload::inst( $_SERVER['DOCUMENT_ROOT'].'_Z/uploads/__ID__.__EXTN__' )
->db( 'stakeholders', 'id', array(
'sh_fileContent' => Upload::DB_CONTENT,
'sh_fileContentType' => Upload::DB_MIME_TYPE,
'sh_fileName' => Upload::DB_FILE_NAME,
'sh_fileSize' => Upload::DB_FILE_SIZE
)
)
)
->setFormatter( 'Format::nullEmpty' )
)
-
I am aware it is not the recommended practice... ↩
how to have json reponse in client server (mysql) datatable use
i have this error
{"draw":1,"recordsTotal":5,"recordsFiltered":5,"data":[null,null,null,null,null]}
2
TypeError: data is null
return data[mSource];
and this is my script
html
id | nom | prenom | grade | organisme | plus de details |
---|
javascript
$('#myModaltab').modal('hide');
table=$('#users').DataTable({
"columns": [
{"data": "id",
"visible":false,
"searchable": false
},
{"data": "nom",
"searchable": true},
{"data": "prenom",
"searchable": true},
{"data": "grade",
"searchable": true},
{"data": "organisme",
"searchable": true},
{
"targets": -1,
"data": null,
"searchable": false,
"orderable":false,
"defaultContent": "<button type='button' class='btn btn-info btn-md u3' ><span class='glyphicon glyphicon-plus-sign'></button>"
},
],
keys: true,
"processing": true,
"serverSide": true,
"stateSave": true,
"ajax": {
url: 'page.php',
type: 'POST',
}
,
scrollX: true,
language: {
processing: "Traitement en cours...",
search: "Rechercher :",
lengthMenu: "Afficher _MENU_ éléments",
info: "Affichage de l'élement _START_ à _END_ sur _TOTAL_ éléments",
infoEmpty: "Affichage de l'élement 0 à 0 sur 0 éléments",
infoFiltered: "(filtré de _MAX_ éléments au total)",
infoPostFix: "",
loadingRecords: "Chargement en cours...",
zeroRecords: "Aucun élément à afficher",
emptyTable: "Aucune donnée disponible dans le tableau",
paginate: {
first: "Premier",
previous: "Précédent",
next: "Suivant",
last: "Dernier"
},
aria: {
sortAscending: ": activer pour trier la colonne par ordre croissant",
sortDescending: ": activer pour trier la colonne par ordre décroissant"
}
}
});
php
define("HOST", "localhost");
define("USER", "root");
define("PASSWORD", "");
define("DB", "bdexepert");
define("MyTable", "expert1");
$connection = mysqli_connect(HOST, USER, PASSWORD, DB) OR DIE("Impossible to access to DB : " . mysqli_connect_error());
$primaryKey = 'id';
/* END DB Config and connection */
/*
* @param (string) SQL Query
* @return multidim array containing data array(array('column1'=>value2,'column2'=>value2...))
*
*/
function getData($sql){
global $connection ;//we use connection already opened
$query = mysqli_query($connection, $sql) OR DIE ("Can't get Data from DB , check your SQL Query " );
$data = array();
foreach ($query as $row ) {
$data[] = $row ;
}
return $data;
}
/* Useful $_POST Variables coming from the plugin */
$draw = $_POST["draw"];//counter used by DataTables to ensure that the Ajax returns from server-side processing requests are drawn in sequence by DataTables
$orderByColumnIndex = $_POST['order'][0]['column'];// index of the sorting column (0 index based - i.e. 0 is the first record)
$orderBy = $_POST['columns'][$orderByColumnIndex]['data'];//Get name of the sorting column from its index
$orderType = $_POST['order'][0]['dir']; // ASC or DESC
$start = $_POST["start"];//Paging first record indicator.
$length = $_POST['length'];//Number of records that the table can display in the current draw
/* END of POST variables */
$recordsTotal = count(getData("SELECT * FROM expert1 where activstate=".$cle));
/* SEARCH CASE : Filtered data */
if(!empty($_POST['search']['value'])){
/* WHERE Clause for searching */
for($i=0 ; $i<count($_POST['columns'])-1;$i++){
$column = $_POST['columns'][$i]['data'];//we get the name of each column using its index from POST request
$where[]="$column like '%".$_POST['search']['value']."%'";
}
$where = "WHERE ".implode(" OR " , $where);// id like '%searchValue%' or name like '%searchValue%' ....
/* End WHERE */
$sql = sprintf("SELECT * FROM %s %s and activstate=%s", MyTable , $where,$cle);//Search query without limit clause (No pagination)
$recordsFiltered = count(getData($sql));//Count of search result
/* SQL Query for search with limit and orderBy clauses*/
$sql = sprintf("SELECT * FROM %s %s and activstate=%s ORDER BY %s %s limit %d , %d ", MyTable , $where ,$cle ,$orderBy, $orderType ,$start,$length );
//echo $sql;
$data = getData($sql);
/* END SEARCH */
}else {
$sql = sprintf("SELECT * FROM %s where activstate=%s ORDER BY %s %s limit %d , %d ", MyTable,$cle ,$orderBy,$orderType ,$start , $length);
// echo $sql ;
$data = getData($sql);
$recordsFiltered = $recordsTotal;
}
/* Response to client before JSON encoding */
$response=array(
"draw"=>intval($draw),
"recordsTotal" =>$recordsTotal,
"recordsFiltered"=>$recordsFiltered,
"data"=>$data
);
// print_r($data);
//echo json_encode($data);
$response=utf8_converter($response);
echo json_encode($response, JSON_UNESCAPED_UNICODE);
} else {
echo "NO POST Query from DataTable";
}
function utf8_converter($array)
{
array_walk_recursive($array, function(&$item, $key){
if(!mb_detect_encoding($item, 'utf-8', true)){
$item = utf8_encode($item);
}
});
return $array;
}
Multi filtering system problem
Hi guy's,
I've created an "extension" to the datatables to project my needs.
It basically consists on a box with many types of filters. Multi checkbox's that are added to a regex string for search purposes, many types of calculations depending on the type of data to check if it's null, bigger than etc to add the result to the regex string and the possibility of having an external filtering data coming from multiple charts. Basicly I'm getting the current data saved at the local storage and editing the search string's from the correct columns.
All this seems pretty "doable", except a problem I'm having.
When loading the chart from the local storage - as explained in the manual from here - it comes everything correct but I can't access in any way to the cache from the search, so that I can create the filtering system.
From what I've understood, when doing:
table.column(table.colReorder.transpose(colIdx)).cache('search').unique().sort().each(function (d) {
The unique() and sort() would "emulate" a change to the datatable, so there should always be cache at the search.
Isn't this the main purpose, like it's explained on the manual?
Thank you all.
Adding new rows to the bottom of the table with server-side processing and scroller
I created table with server-side processing and scroller (something as shown here: Server-side processing (5,000,000 rows)) and everything works fine. Unfortunately, I have additional requirements regarding this table.
Sometimes I have to add new rows to the bottom of the table. What's more, I would like to scroll it so that the new data will be visible all the time. It's important to do it with server-side processing, because table could have an enormous amount of rows.
Is it possible to force the table to load data from given position (start in sent parameters)? Is there any way to make such functionality with DataTables? I will be extremely grateful for any help and suggestions how to solve my problem.
Table callback earlier than CretaedRow callback
Hi,
Is there callback that is called when table is re initialized (not only redrawed)?
I have dynamic datatable, where rows can be added and table may be initialized with different data during page life.
I need to control that id column contains unique number, and doing that by concatenating to the id its instance number, in rowCreated callback.
I want to store existing IDs in an object, and on each row creation to go over already added IDs and add current one.
But I need to declare\initialize an object before rowCreated callback is called.
As table can be reinitialized I need to set object to empty when initialization called.
Where can I do that? Is there a callback that called when table is reinitialized, or maybe when rows are removed so I can remove IDs of deleted rows?
Thanks,
Riki.
Server side processing (5000000) rows
it will be very helpful for me if you post your sample code where you are doing Server-side processing (5,000,000 rows) and it will be fetched from db using ajax request and passing some parametrs to ajax request to fetch data.
How i pass a value from jquery datatable to query string of a link in that table?
Here i attach screen shot, I want to pass id from each column as query string to inidividual link