How to have extra column than data?

How to have extra column than data?

anjibmananjibman Posts: 115Questions: 10Answers: 0

If I have 8 columns in the table but server only return 6 columns value how I can tell DataTable to fill other two columns with some value? I tried this but getting Requested unknown parameter error.

"processing": true,
        "serverSide": true,
        "ajax": "/networkattorneys/cases/openCases.htm",
        "columns": [
            { "data": "id" },
            { "data": "firstName" },
            { "data": "lastName" },
            { "data": "groupName" },
            { "data": "requestDate" },
            { "data": "status" },
            null,
            null
        ]

This question has an accepted answers - jump to answer

Answers

  • rhinorhino Posts: 80Questions: 2Answers: 17
    edited July 2014

    Perhaps this example will help?

  • anjibmananjibman Posts: 115Questions: 10Answers: 0
    edited July 2014

    I tried this

     "columnDefs": [
                {
                    "targets": 0,
                    "data": "memberId",
                    "render": function(data, type, row, meta) {
                        alert(data.memberId);
                        return '<a href="' + data.memberId + '">' + data.memberId + '</a>';
                    }
                }
             ],
            "columns": [
                        { "data": null },
                        { "data": "firstName" },
                        { "data": "lastName" },
                        { "data": "groupName" },
                        { "data": "caseOpenDate" },
                        { "data": "status" },
                        { "data": "partyIdConsumer" },
                        { "data": "caseEventId" }
            ],
    

    but it never get after function(..). From line 5 its jumps to 11.

  • rhinorhino Posts: 80Questions: 2Answers: 17
    edited July 2014

    I'm a bit confused, why say that column 0 is { "data": null } and then later say "data": "memberId"? Couldn't you just make it { "data": "memberId"} in the "columns": definition?

  • anjibmananjibman Posts: 115Questions: 10Answers: 0

    I wan to use display memberID value as hyerlink.

  • rhinorhino Posts: 80Questions: 2Answers: 17

    Try this:

    "columnDefs": [
               {
                   "targets": 0,
                   //"data": "memberId",
                   "render": function(data, type, row, meta) {
                       //alert(data.memberId);
                       //return '<a href="' + data.memberId + '">' + data.memberId + '</a>';
                       return '<a href="' + data + '">' + data + '</a>';
                   }
               }
            ],
           "columns": [
    //                   { "data": null },
                       { "data": "memberId" },
                       { "data": "firstName" },
                       { "data": "lastName" },
                       { "data": "groupName" },
                       { "data": "caseOpenDate" },
                       { "data": "status" },
                       { "data": "partyIdConsumer" },
                       { "data": "caseEventId" }
           ],
    
  • anjibmananjibman Posts: 115Questions: 10Answers: 0

    I don't think we can comment out line 13. Even with that its not displaying link instead it displayed [object Object]. I tried with data.memberId in line 8 too same result [object Object]

  • anjibmananjibman Posts: 115Questions: 10Answers: 0

    Got the solution:

    "columns": [
                        { 
                            "data": null,
                            "render": function(data, type, row, meta) {
                                return '<a href="' + data.memberId + '">' + data.memberId + '</a>';
                            }
                        },
                        { "data": "firstName" },
                        { "data": "lastName" },
                        { "data": "groupName" },
                        { "data": "caseOpenDate" },
                        { "data": "status" },
                        { "data": "partyIdConsumer" },
                        { "data": "caseEventId" }
            ],
    

    all can be done with render in columns

  • rhinorhino Posts: 80Questions: 2Answers: 17

    Well I'm glad you found a solution :) Though I admit I'm a bit confused about where memberId comes from? Where does that property come from?

  • anjibmananjibman Posts: 115Questions: 10Answers: 0
    edited July 2014

    Its in JSON response (data) too along with other. That's why I am able to do data.memberId.

  • rhinorhino Posts: 80Questions: 2Answers: 17

    Nevermind. It seems that, when a table's column is defined with data: null, then the data parameter of the render() function is equivalent to the row parameter. I did not realize this!

  • rhinorhino Posts: 80Questions: 2Answers: 17
    edited July 2014 Answer ✓

    I'd also like to point out that this should work as well:

    "columns": [
                        { 
                            "data": "memberId",
                            "render": function(data, type, row, meta) {
                                return '<a href="' + data + '">' + data + '</a>';
                            }
                        },
                        { "data": "firstName" },
                        { "data": "lastName" },
                        { "data": "groupName" },
                        { "data": "caseOpenDate" },
                        { "data": "status" },
                        { "data": "partyIdConsumer" },
                        { "data": "caseEventId" }
            ],
    

    If I'm understanding the DT API correctly.

This discussion has been closed.