0
상황에 따라 데이터 테이블에서 특정 행의 데이터를 가져 오려고합니다. DataTable을 처음 사용합니다.데이터 테이블에서 행 데이터를 가져 오는 방법
여기 상황은
입니다. 내 데이터 테이블 내용은 그림에 나와 있습니다. 내가 이름을 통과하고 같은
울부 짖는 소리는 삭제 버튼에 내 데이터 테이블
$(document).ready(function() {
var table =$('#example').dataTable({
\t
\t "processing": true,
\t "ajax": {
\t \t \t \t "url":'/myWeb/Controller/getUserList',
\t \t \t \t "dataSrc":""
\t \t \t }, \t \t \t
\t "columns": [
\t { "data": "userName"},
\t \t \t \t { "data": "roles" },
\t \t \t \t
\t \t \t \t \t
\t \t \t \t \t
\t \t \t {
\t data: "userName",
\t render: function (data, type, row) { \t
\t \t
\t if (type === 'display') {
\t return '<button type="button" id='+data+' class="btn btn-default btn-sm" data-toggle="modal" data-target="#editUser" data-whatever="@getbootstrap()" onclick="getUserName(this.id)" > <span class="glyphicon glyphicon-pencil"></span> Edit </button>'; \t
\t }
\t //alert(data);
\t return data;
\t }
\t },
\t {
\t \t data : \t "userName",
\t if (type === 'display') {
\t return '<button type="button" id='+data+' class="btn btn-default btn-sm" onclick="countUserRecord(this.id)"> <span class="glyphicon glyphicon-trash"></span> Delete </button>'; \t
\t }
\t //alert(data);
\t return data;
\t }
\t }
\t \t
\t \t ],
"paging": false,
"info": false,
"filter": false,
"sort": \t \t false
});
});
코드입니다, 나는 또한 역할을 통과하려면, 그래서 나는이
시도role = row.roles;
userName = row.userName;
status = row.status;
alert("username :"+userName+" role: "+role);
\t
하지만 이렇게 할 때 각 사용자마다 다른 역할을하고 있습니다. 나에게 잘못된 사용자의 역할을 부여합니다.
벨로우즈는 DB에서 가져 오는 내 Json 구조입니다. 나는 사용자 삭제 버튼을 클릭하면
[
{"userName":"admin",
"password":null,
"roles":"Admin",
"status":"Active",
"email":"emailAdmin"},
{"userName":"varun",
"password":null,
"roles":"User",
"status":"Active",
"email":"emailVarun"},
{"userName":"bob",
"password":null,
"roles":"Admin",
"status":"Active",
"email":"undefined"}
]