dataTable not working out

dataTable not working out

markl17markl17 Posts: 9Questions: 1Answers: 0
edited June 2014 in Free community support

here is my jsfiddle http://jsfiddle.net/V7Hw9/1/
with data please let me know how to make Name to show up

Answers

  • markl17markl17 Posts: 9Questions: 1Answers: 0
  • allanallan Posts: 63,498Questions: 1Answers: 10,471 Site admin

    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

  • markl17markl17 Posts: 9Questions: 1Answers: 0

    thank you so much I wouldnt have seen that

  • markl17markl17 Posts: 9Questions: 1Answers: 0
    edited June 2014

    why does this code runs in jsfiddle http://jsfiddle.net/V7Hw9/2/ but not in the browser

  • allanallan Posts: 63,498Questions: 1Answers: 10,471 Site admin

    You would need to link us to the page with the error. Most likely your Javascript developer console will give you a clue.

    Allan

  • markl17markl17 Posts: 9Questions: 1Answers: 0

    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

  • allanallan Posts: 63,498Questions: 1Answers: 10,471 Site admin

    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

  • markl17markl17 Posts: 9Questions: 1Answers: 0

    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!!

  • markl17markl17 Posts: 9Questions: 1Answers: 0

    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

  • markl17markl17 Posts: 9Questions: 1Answers: 0

    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

  • markl17markl17 Posts: 9Questions: 1Answers: 0
    edited June 2014

    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,

        "aoColumns": [
            { "mDataProp": "Name" },
            { "mDataProp": "Position" },
            { "mDataProp": "Office" },
            { "mDataProp": "Extn" },
            { "mDataProp": "Start_date" },
            { "mDataProp": "Salary" }
        ]
    } );
    
This discussion has been closed.