It is possible to have two value in single column datatable?

It is possible to have two value in single column datatable?

mastersusemastersuse Posts: 61Questions: 28Answers: 0

It is possible to have two value in single column datatable? I want both data: "login" and data: "user_id" as below be in one column which will carry two values which is login and user_id.

If it is possible, how to implement that way? please help and guide me.

{ data : "login",
    render: function(data){
        return  "<span title='Reset Password' onclick='reset_password(&quot;"+data+"&quot;)'></span>";
    }
},
{ data : "user_id",
    render: function(data){
        return  "<span title='Edit' onclick='edit_user(&quot;"+data+"&quot;)'></span>"+
                "<span title='Delete' onclick='delete_user(&quot;"+data+"&quot;)'></span>";
    }
}

This question has accepted answers - jump to:

Answers

  • Alexandr45Alexandr45 Posts: 30Questions: 1Answers: 3
    Answer ✓

    {
    data: null,
    render: function ( data, type, row ) {
    return data.table.login+' '+data.table.user_id;
    }

  • mastersusemastersuse Posts: 61Questions: 28Answers: 0

    I am doing like this.

    { data : null,
        render: function ( data, type, row ) {
            return  "<span title='Reset Password' onclick='reset_password(&quot;"+data.table.login+"&quot;)'></span>"+
                    "<span title='Edit User' onclick='edit_user(&quot;"+data.table.user_id+"&quot;)'></span>&nbsp;"+
                    "<span title='Delete User' onclick='delete_user(&quot;"+data.table.user_id+"&quot;)'></span>";
        }
    },
    

    But this error appear at console.

  • Alexandr45Alexandr45 Posts: 30Questions: 1Answers: 3

    data.table.login,

    "table" is the name of your table in the database

  • mastersusemastersuse Posts: 61Questions: 28Answers: 0

    yes already doing as suggested above but still appear same error.

    <table id="myTable" class="table table-striped dt-responsive nowrap" style="width:100%">
        <thead>
            <tr>
                <th class="text-center">Action</th>
            </tr>
        </thead>
    </table>
    
    var myTestTable = $('#myTable').DataTable({
        { data : null,
            render: function ( data, type, row ) {
                return  "<span title='Reset Password' onclick='reset_password(&quot;"+data.myTestTable.login+"&quot;)'></span>"+
                        "<span title='Edit User' onclick='edit_user(&quot;"+data.myTestTable.user_id+"&quot;)'></span>&nbsp;"+
                        "<span title='Delete User' onclick='delete_user(&quot;"+data.myTestTable.user_id+"&quot;)'></span>";
            }
        },
    });
    
  • kthorngrenkthorngren Posts: 21,341Questions: 26Answers: 4,954
    Answer ✓

    Take a look at the columns.render docs for the description of the function parameters. data is the data for the column and row is full dataset for the row. You will want to use the row parameter and access the data like this: row.login and row.user_id. The row data will look like the data structure you defined using columns.data. The table name should not be used as part of accessing the data.

    Something like this:

            render: function ( data, type, row ) {
                return  "<span title='Reset Password' onclick='reset_password(&quot;"+row.login+"&quot;)'></span>"+
                        "<span title='Edit User' onclick='edit_user(&quot;"+row.user_id+"&quot;)'></span>&nbsp;"+
                        "<span title='Delete User' onclick='delete_user(&quot;"+row.user_id+"&quot;)'></span>";
            }
    

    Kevin

  • mastersusemastersuse Posts: 61Questions: 28Answers: 0

    Thank you both of you guys, I combined both solutions and solve my problem.

This discussion has been closed.