Getting properties of object returned by serversideProcessing even if not used in any column V1.10

Getting properties of object returned by serversideProcessing even if not used in any column V1.10

dachdach Posts: 6Questions: 2Answers: 0
edited July 2014 in Free community support

Hello everyone,

I have created a server side script to return an array of objects to the datatable plugin.
Lets imagine I have 15 properties in this object and I just want to display 10 of them in columns.

During the "createdRow", I will be able to access to my object by the second parameter of the function but the 5 properties not shown in any column will be missing in this object.

I know that I can add 5 more columns and force them to be hidden but does a better way to retrieve these information exist?

Thanks.

Dach

This question has an accepted answers - jump to answer

Answers

  • allanallan Posts: 61,446Questions: 1Answers: 10,054 Site admin
    Answer ✓

    The solution is relatively simple - just define the 10 columns you want with columns.data set to access the object property for each column you want to be visible. DataTables won't do anything with the other data in the object (although it will still be in the object).

    Allan

  • dachdach Posts: 6Questions: 2Answers: 0

    Thanks for your fast answer.

    It was so easy I don't know why I never tried it.

    Thank you for this awesome tool.

  • dachdach Posts: 6Questions: 2Answers: 0

    Well, in fact I misunderstood your answer.
    I thought you asked me to only add the "data" property in the column definition.

    In fact I tried your solution but I already did that before posting and it doesn't work.

    Let's take this example :

    Here is my columns definiton :
    columns: [
    { data: "Id", title : "Id" },
    { data: "Designation", title : "Designation" }
    ]

    Then the returned object (by the ajax function) which has this structure :
    object = {
    Id: 1,
    Designation: "test",
    Comment: "test comment"
    }

    In the rowCallback event (rowCallback: function (row, object, rowId)), the object var will have this structure :
    object = {
    Id: 1,
    Designation: "test"
    }

    If I add a new column which contains the column "data" with value "Comment", I will have my full object.

    So I don't understand your reply, maybe I am doing something wrong.

  • allanallan Posts: 61,446Questions: 1Answers: 10,054 Site admin

    If I add a new column which contains the column "data" with value "Comment", I will have my full object.

    Yes. Is that not what you want? I'm afraid I don't understand the problem.

    Let's try it with an actual test case. Consider: http://live.datatables.net/viqamixa/1/edit

    You'll see there are three columns. However, if you look at the JSON data source, you'll be able to see the data object contains a lot more information than just those three columns:

            {
                "name": "Tiger Nixon",
                "position": "System Architect",
                "salary": "$320,800",
                "start_date": "2011\/04\/25",
                "office": "Edinburgh",
                "extn": "5421"
            },
    

    Allan

  • dachdach Posts: 6Questions: 2Answers: 0

    I just realized that this was caused by my server side script.
    I only request the fields corresponding to the columns' data...
    Sorry for the time you spent for nothing :(

This discussion has been closed.