Where clause - which file and for multiple tables
Where clause - which file and for multiple tables
Jokris
Posts: 5Questions: 2Answers: 0
I am unsure where I should put the where clause. Would like to produce two different tables for two different pages: "youngpeople.php" and "oldpeople.php"
"youngpeople.php" should have a table with only people under 18, created with the following statement
$editor
->where( 'age', 18, '<' );
"oldpeople.php" should have people 18 or above
$editor
->where( 'age', 18, '>=' );
This is the code I use
var editor; // use a global for the submit and return data rendering in the examples
$(document).ready(function() {
editor = new $.fn.dataTable.Editor( {
ajax: "../php/staff.php",
table: "#example",
fields: [ {
label: "First name:",
name: "first_name"
}, {
label: "Last name:",
name: "last_name"
}, {
label: "Position:",
name: "position"
}, {
label: "Office:",
name: "office"
}, {
label: "Extension:",
name: "extn"
}, {
label: "Start date:",
name: "start_date",
type: "datetime"
}, {
label: "Salary:",
name: "salary"
}
]
} );
$('#example').DataTable( {
dom: "Bfrtip",
ajax: "../php/staff.php",
columns: [
{ data: null, render: function ( data, type, row ) {
// Combine the first and last names into a single table field
return data.first_name+' '+data.last_name;
} },
{ data: "position" },
{ data: "office" },
{ data: "extn" },
{ data: "start_date" },
{ data: "salary", render: $.fn.dataTable.render.number( ',', '.', 0, '$' ) }
],
select: true,
buttons: [
{ extend: "create", editor: editor },
{ extend: "edit", editor: editor },
{ extend: "remove", editor: editor }
]
} );
} );
This question has an accepted answers - jump to answer
This discussion has been closed.
Answers
The
where
clause would go into the PHP script (staff.php
in your above example). The documentation for thewhere
condition contains a detailed explanation and examples.Allan