dataTable not working out
dataTable not working out
markl17
Posts: 9Questions: 1Answers: 0
here is my jsfiddle http://jsfiddle.net/V7Hw9/1/
with data please let me know how to make Name to show up
This discussion has been closed.
Answers
jsfiddle is http://jsfiddle.net/V7Hw9/1/
Your JSON has
"Name "
, but your DataTable is looking for"Name"
- note the space in your JSON. I'd suggest that your JSON output might contain a typo...Allan
thank you so much I wouldnt have seen that
why does this code runs in jsfiddle http://jsfiddle.net/V7Hw9/2/ but not in the browser
You would need to link us to the page with the error. Most likely your Javascript developer console will give you a clue.
Allan
http://kosher-time.netai.net/rowex.html apparently assigning to thevalue that I get out of console.dir(a);works so now I dont really know what to say
Its trying to load from
"http://localhost:5984/two2/_design/rows/_view/data1
- which isn't going to work for anyone but you :-). Can you change it please.Is there a reason you aren't using
ajax
to get the data for you?Allan
as you notice int he code if I assign a to that string which I copied from console.log than everything works out but the moment I let it go with out assignment it all goes kabueee!!
allan I also followed an example this is the only one so far i was able to get something out whne i try this $('#example').dataTable( {
"ajax" : a,
"dataSrc": "",
"aoColumns": [
{ "mDataProp": "Name" },
{ "mDataProp": "Position" },
{ "mDataProp": "Office" },
{ "mDataProp": "Extn" },
{ "mDataProp": "Start_date" },
{ "mDataProp": "Salary" }
]
} );
it doesnt work unless i didnt understand the manual which could also be the truth
this is what comes out of couch db as json {
"total_rows": 57,
"offset": 0,
"rows": [
{
"id": "50132008f55fc0cceb01e2399b0796d5",
"key": null,
"value": {
"_id": "50132008f55fc0cceb01e2399b0796d5",
"_rev": "1-b5327e71f7d6cce8d726f0df5e2f54bd",
"Name": "Airi Satou",
"Position": "Accountant",
"Office": "Tokyo",
"Extn": 5407,
"Start_date": "2008/11/28",
"Salary": "$162,700"
}
},
{
"id": "50132008f55fc0cceb01e2399b07a4b7",
"key": null,
"value": {
"_id": "50132008f55fc0cceb01e2399b07a4b7",
"_rev": "1-29fd34ab8f7941d1b8fe33ee74fbc880",
"Name": "Angelica Ramos",
"Position": "Chief Executive Officer (CEO)",
"Office": "London",
"Extn": 5797,
"Start_date": "2009/10/09",
"Salary": "$1,200,000"
}
},
then I reasemmble make it look the way I understand your programm wants it to look like
i resolved my own problems here is the code , it came to me once I realized what was rong
var a = "[";
$.ajax({ type: "GET",
url: "http://localhost:5984/two2/_design/rows/_view/data1",
dataType: "json",
async: false,
success: function (data){data.rows.forEach(
function (change){
a +=
'{\"' +'Name\":\"'+ change.value.Name +
'\",\"' + 'Position\":\"' + change.value.Position +
'\",\"' + 'Office\":\"' + change.value.Office +
'\",\"' + 'Extn\":\"' + change.value.Extn +
'\",\"' + 'Start_date\":\"' + change.value.Start_date +
'\",\"' + 'Salary\":\"' + change.value.Salary +'\"},'
}
);}
});
a = removeLastComma(a);
a+="]";
var c = jQuery.parseJSON( a);//converts the constructed string into a json obj
$('#example').dataTable( {
"aaData" : c,