私はDataTableの内部の状態を定義したい。..
だから基本的に私は、データの出力をフィルタリングするためにセッションを使用しています。
ケース
私はジョンとしてログイン:そう、私は以下の条件を与えたい
| Name | Quantity | Action |
| John | 400 | #**CanSeeEditButton** |
| Mia | 300 | #CannotSeeEditButton |
| John | 200 | #**CanSeeEditButton** |
| Alex | 900 | #CannotSeeEditButton |
は、私がsession = userId
を持っており、このレコードのテーブルには、あまりにもそれを持っています私はsession userId = record userId
と一致したい。 id
がプライマリです(ユーザーIDではありません)
私はそれを調整する方法についていません。ここでは、userId
フィールドにアクセスする例full['userId']
ため、full
変数を使用して完全なデータセットにアクセスすることができます私のコード
<script>
$(document).ready(function() {
$('#dataTable').DataTable({
serverSide : true,
ajax : {
url : '{{ this.url.getBaseUri() }}productionstocklog/read',
method : 'POST'
},
columns: [
{data: "name"},
{data: "qty"},
// I want to give condition below, I have session = userId, and this record table have it too, so I want to match session userId = record userId. and id below is primary Key of table (not userID)
{% if this.session.get('auth')['userId'] == data: "userId" // <-- how to get data:userId in Datatables ? %}
{data: "id", render : function(data, type, full, meta){
return ' <a data-toggle="modal" data-target="#edit" class="btn btn-xs btn-success icon-pencil icon" ' +
' onclick="EditShow(\''+data+'\');"> Edit </a>' +
' <a href="{{ this.url.getBaseUri() }}productionstocklog/delete/'+data+'" class="btn btn-xs btn-danger icon-ban icon" ' +
' onclick="return confirm(\'Delete?\');"> Delete </a> '
}}
{% endif %}
]
});
});
</script>
@Timothy、こんにちは.. U再び!
は以下
columns
オプションをお試しください!仲間よ! –