0

Is their a way where I can bind an Id with row in datatables?

I get 3 columns from my database and display 2 in datatable to user, but what I want is to attach 1st column (which is Id) to whole row so that when user clicks on a particular row, it takes user to different page depending on Id.

ex

"aoColumns": [
                    { "mData": "Id",
                        "bSearchable": false,
                        "bSortable": false,
                        //"bVisible": false,
                        "fnRender": function (oObj) {
                            return '<a href=\"Details/' + oObj.aData[0] + '\">Id</a>';
                        }
                     },

                    { "mData": "FullName" },
                    { "mData": "Age" }
                ]

and this is what I get in Json

{"sEcho":"1","iTotalRecords":1,"iTotalDisplayRecords":1,"aaData":[{"Id":425,"FullName":"xxx","Age":21,}]}

also oObj.aData[0] always comes out as undefined? I am showing FullName and Age but want user to click on row level.

Any help will be appreciated

Thanks

1 Answer 1

1

From the DataTables web site:

Often when using server-side processing you will find that it can be useful to have a specific ID on each row (the row ID from the database for example). By assigning the ID you want to apply to each row using the property DT_RowId of the data source object for each row, DataTables will automatically add it for you.

http://datatables.net/release-datatables/examples/server_side/ids.html

In short, you want to use "DT_RowID" for the name in your JSON array, not simply "ID".

You can then bind an event like so:

jQuery('#table tbody tr').live('dblclick', function () { viewRow(this.id); } );

The "live" means this event will occur for any row that is added to the DataTable dynamically, not just rows that were there when the table was created. If you are never adding rows dynamically, you could just bind to the dbclick event itself.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.