mDataprop + paging + searching + server-side

mDataprop + paging + searching + server-side

numberonenumberone Posts: 86Questions: 0Answers: 0
edited June 2011 in General
Is it possible to send data of selected columns that has mDataprop ?

im trying to make a query for paging and searching but couldnt identify the column on server side.

it would be great if we could have sent something like :

sDataprop : 'username, email, blabla' only selected elements here with the order, like sColumns.

what do you think ?

or is there another alternative to do that ?

Thanks.

Replies

  • allanallan Posts: 63,213Questions: 1Answers: 10,415 Site admin
    I'm not sur what you mean by "selected" I'm afraid. DataTables doesn't have any built in support for selected columns - although it is of course possible by building on top of it - in which case I would suggest sending the extra information to the server something like this: http://datatables.net/examples/server_side/custom_vars.html

    Allan
  • numberonenumberone Posts: 86Questions: 0Answers: 0
    lets say my json like :

    [code]
    [
    { "id": "1",
    "username": "Orion",
    "email": "johndoe@email.com",
    "group_name": "User"
    },
    { "id": "2",
    "username": "Saturn",
    "email": "saturn@email.com",
    "group_name": "User"
    }
    ]
    [/code]

    and my table has 3 columns with this column order:
    [code]
    "aoColumns": [
    { "mDataProp": "group_name" },
    { "mDataProp": "username" },
    { "mDataProp": "email"},
    ],
    [/code]

    so, when i try ordering by group_name, at server-side iSortCol_0 equals to zero.

    i want to sent a data like
    [code]
    sDataprop : 'group_name, username, email'
    [/code]

    so i can handle it like :
    [code]
    mDataprop = explode(',' , $_POST['sDataprop']);
    $order_by = mDataprop[ $_POST['iSortCol_0'] ]; // $order_by will be group_name
    [/code]
  • numberonenumberone Posts: 86Questions: 0Answers: 0
    ok, i got it ^^ ty allan.

    [code]
    'fnServerData': function(sSource, aoData, fnCallback)
    {
    aoData.push( { "name": "sDataprop", "value": "group_name,username,email" } );
    $.ajax
    ({
    'dataType': 'json',
    'type' : 'POST',
    'url' : sSource,
    'data' : aoData,
    'success' : fnCallback
    });
    },
    });
    [/code]

    it would be nice if we had have that by default ^^

    again thank you very much.
  • allanallan Posts: 63,213Questions: 1Answers: 10,415 Site admin
    This is what sName is for - you would need to specify sName for each column (like you have done for mDataProp) and that will be passed to the server.

    Allan
  • numberonenumberone Posts: 86Questions: 0Answers: 0
    unlike mDataprop, sName needs all columns to be specified or it gives errors. with mDataprop u can show only what you need. plus i couldnt make mDataprop work with sName its giving error.


    Whatever, ty for ur reply.
  • numberonenumberone Posts: 86Questions: 0Answers: 0
    hey allan,

    could you gimme an example how can i use both mDataprop and sName together ?

    ? couldnt make it work :(

    thanks
  • allanallan Posts: 63,213Questions: 1Answers: 10,415 Site admin
    Can you not just do:

    [code]
    { "mDataProp": "name", "sName": "name" },
    ...
    [/code]
    Then the server will be able to figure out which column is which. Of course since you are using objects in the return then it's not important in the returned JSON since DataTables will do the mapping automatically.

    Allan
This discussion has been closed.