testing simple join
testing simple join
Hi there,
I'm performing a simple join whereby I'm accessing fields from three Tables: employees, landlines, and mobile
From the employees table, I'm obtaining fields LASTNAME and FIRSTNAME.
From the landlines table, I'm obtaining the field LANDLINE_NUMBER.
From the mobile table, I'm obtaining the field MOBILE_NUMBER.
Straight forward so far, right?
Ok...so I'm loading up DataTables with the JSON string from the server side which looks like this:
{"id":"-1","error":"","fieldErrors":[],"data":[],"row":[],"aaData":[{"DT_RowId":"38","LASTNAME":"Abaga","FIRSTNAME":"Eunice","landlines":{"LANDLINE_NUMBER":"424-8808"},"mobile":{"MOBILE_NUMBER":"476-6393"}},{"DT_RowId":"39","LASTNAME":"Abdelhak","FIRSTNAME":"Semali","landlines":{},"mobile":{}},{"DT_RowId":"40","LASTNAME":"Abenheimer","FIRSTNAME":"Susan","landlines":{"LANDLINE_NUMBER":"563-0594"},"mobile":{"MOBILE_NUMBER":"565-0169"}},{"DT_RowId":"41","LASTNAME":"Aikenhead","FIRSTNAME":"Sherri","landlines":{"LANDLINE_NUMBER":"424-7942"},"mobile":{}},{"DT_RowId":"42","LASTNAME":"Aiton","FIRSTNAME":"Samantha","landlines":{"LANDLINE_NUMBER":"424-7750"},"mobile":{"MOBILE_NUMBER":"233-1106"}},{"DT_RowId":"43","LASTNAME":"Akindoju","FIRSTNAME":"Toyin","landlines":{"LANDLINE_NUMBER":"424-7510"},"mobile":{}},{"DT_RowId":"44","LASTNAME":"Alladina","FIRSTNAME":"Sameer","landlines":{"LANDLINE_NUMBER":"424-0178"},"mobile":{}},{"DT_RowId":"45","LASTNAME":"Allen","FIRSTNAME":"Daniel","landlines":{"LANDLINE_NUMBER":"424-0845"},"mobile":{"MOBILE_NUMBER":"223-0825"}}, ...}
HTML:
[code]
<!doctype html>
jQuery Example
@import "css/demo_page.css";
@import "css/jquery.dataTables.css";
@import "css/TableTools.css";
@import "css/dataTables.editor.css";
#big_wrapper{
border: 1px solid black;
width:1000px;
margin: 20px auto;
text-align:left;
}
CRUD DataTable Example
This example demonstrates the joining of three tables: employees, landlines, and mobile
LASTNAME
FIRSTNAME
LANDLINE
MOBILE
LASTNAME
FIRSTNAME
LANDLINE
MOBILE
[/code]
JAVASCRIPT:
[code]
var editor; // use a global for the submit and return data rendering in the examples
$(document).ready(function() {
editor = new $.fn.dataTable.Editor( {
"ajaxUrl": "http://localhost:8080/JQuery/join.jsp",
"domTable": "#employees",
fields": [ {
"label": "LASTNAME:",
"name": "LASTNAME",
"type": "text"
}, {
"label": "FIRSTNAME:",
"name": "FIRSTNAME",
"type": "text"
}, {
"label": "LANDLINE:",
"name": "landlines.LANDLINE_NUMBER",
"type": "text"
}, {
"label": "MOBILE:",
"name": "mobile.MOBILE_NUMBER",
"type": "text"
}
]
} );
$('#employees').dataTable( {
"sDom": "Tfrtip",
"sAjaxSource": "http://localhost:8080/JQuery/join.jsp",
"aoColumns": [
{ "mData": "LASTNAME" },
{ "mData": "FIRSTNAME" },
{ "mData": "landlines.LANDLINE_NUMBER" },
{ "mData": "mobile.MOBILE_NUMBER" }
],
"oTableTools": {
"sRowSelect": "single",
"aButtons": [
{ "sExtends": "editor_create", "editor": editor },
{ "sExtends": "editor_edit", "editor": editor },
{ "sExtends": "editor_remove", "editor": editor }
]
}
} );
} );
[/code]
Basically, DataTables loads as expected but I get the error message: DataTables warning (table id = 'employees'):
requested unknown parameter 'landlines.LANDLINE_NUMBER' from the data source for row 1. Now, am I getting this message because on row 1 that particular record doesn't have a landline number assigned? Not everyone gets a phone line or a mobile device, so some records will undoubtedly show an empty set of curly braces for both LANDLINE_NUMBER and MOBILE_NUMBER. Or am I getting this message for some other reason? Please advise.
Alan
I'm performing a simple join whereby I'm accessing fields from three Tables: employees, landlines, and mobile
From the employees table, I'm obtaining fields LASTNAME and FIRSTNAME.
From the landlines table, I'm obtaining the field LANDLINE_NUMBER.
From the mobile table, I'm obtaining the field MOBILE_NUMBER.
Straight forward so far, right?
Ok...so I'm loading up DataTables with the JSON string from the server side which looks like this:
{"id":"-1","error":"","fieldErrors":[],"data":[],"row":[],"aaData":[{"DT_RowId":"38","LASTNAME":"Abaga","FIRSTNAME":"Eunice","landlines":{"LANDLINE_NUMBER":"424-8808"},"mobile":{"MOBILE_NUMBER":"476-6393"}},{"DT_RowId":"39","LASTNAME":"Abdelhak","FIRSTNAME":"Semali","landlines":{},"mobile":{}},{"DT_RowId":"40","LASTNAME":"Abenheimer","FIRSTNAME":"Susan","landlines":{"LANDLINE_NUMBER":"563-0594"},"mobile":{"MOBILE_NUMBER":"565-0169"}},{"DT_RowId":"41","LASTNAME":"Aikenhead","FIRSTNAME":"Sherri","landlines":{"LANDLINE_NUMBER":"424-7942"},"mobile":{}},{"DT_RowId":"42","LASTNAME":"Aiton","FIRSTNAME":"Samantha","landlines":{"LANDLINE_NUMBER":"424-7750"},"mobile":{"MOBILE_NUMBER":"233-1106"}},{"DT_RowId":"43","LASTNAME":"Akindoju","FIRSTNAME":"Toyin","landlines":{"LANDLINE_NUMBER":"424-7510"},"mobile":{}},{"DT_RowId":"44","LASTNAME":"Alladina","FIRSTNAME":"Sameer","landlines":{"LANDLINE_NUMBER":"424-0178"},"mobile":{}},{"DT_RowId":"45","LASTNAME":"Allen","FIRSTNAME":"Daniel","landlines":{"LANDLINE_NUMBER":"424-0845"},"mobile":{"MOBILE_NUMBER":"223-0825"}}, ...}
HTML:
[code]
<!doctype html>
jQuery Example
@import "css/demo_page.css";
@import "css/jquery.dataTables.css";
@import "css/TableTools.css";
@import "css/dataTables.editor.css";
#big_wrapper{
border: 1px solid black;
width:1000px;
margin: 20px auto;
text-align:left;
}
CRUD DataTable Example
This example demonstrates the joining of three tables: employees, landlines, and mobile
LASTNAME
FIRSTNAME
LANDLINE
MOBILE
LASTNAME
FIRSTNAME
LANDLINE
MOBILE
[/code]
JAVASCRIPT:
[code]
var editor; // use a global for the submit and return data rendering in the examples
$(document).ready(function() {
editor = new $.fn.dataTable.Editor( {
"ajaxUrl": "http://localhost:8080/JQuery/join.jsp",
"domTable": "#employees",
fields": [ {
"label": "LASTNAME:",
"name": "LASTNAME",
"type": "text"
}, {
"label": "FIRSTNAME:",
"name": "FIRSTNAME",
"type": "text"
}, {
"label": "LANDLINE:",
"name": "landlines.LANDLINE_NUMBER",
"type": "text"
}, {
"label": "MOBILE:",
"name": "mobile.MOBILE_NUMBER",
"type": "text"
}
]
} );
$('#employees').dataTable( {
"sDom": "Tfrtip",
"sAjaxSource": "http://localhost:8080/JQuery/join.jsp",
"aoColumns": [
{ "mData": "LASTNAME" },
{ "mData": "FIRSTNAME" },
{ "mData": "landlines.LANDLINE_NUMBER" },
{ "mData": "mobile.MOBILE_NUMBER" }
],
"oTableTools": {
"sRowSelect": "single",
"aButtons": [
{ "sExtends": "editor_create", "editor": editor },
{ "sExtends": "editor_edit", "editor": editor },
{ "sExtends": "editor_remove", "editor": editor }
]
}
} );
} );
[/code]
Basically, DataTables loads as expected but I get the error message: DataTables warning (table id = 'employees'):
requested unknown parameter 'landlines.LANDLINE_NUMBER' from the data source for row 1. Now, am I getting this message because on row 1 that particular record doesn't have a landline number assigned? Not everyone gets a phone line or a mobile device, so some records will undoubtedly show an empty set of curly braces for both LANDLINE_NUMBER and MOBILE_NUMBER. Or am I getting this message for some other reason? Please advise.
Alan
This discussion has been closed.
Replies
We noticed this as well on some. Basically we had to return one result per column even if it was blank.
I don't know what it is you're trying to tell me. I know that row_39 which is row 1 in the DataTable has no phone line or mobile number. That's ok from my perspective. But I didn't expect DataTable to complain about it. Unless there's some property I'm supposed to set to tell it that blank responses are ok? Are you suggesting that maybe I need to include some sort of default value for those that don't have a landline or mobile number?
Alan
> Unless there's some property I'm supposed to set to tell it that blank responses are ok?
This one! You can use sDefaultContent to tell DataTables what to use in the event of data not being available (or being null).
The default behaviour is to throw up a warning saying that the data is not available, but with sDefaultContent you can specifically tell DataTables that this is okay. You can use it to show an empty string, or something more elaborate like `Not set` .
Regards,
Allan
Alan