Я пытаюсь открыть модальный тег <a>
, нажав jquery, но когда я нажимаю <a>
, тег jquery не нажимается. Может быть потому, что я получаю таблицу динамически от контроллера в формате JSON
, а она не привязана к JS. хотя я получаю результаты, на мой взгляд, идеальная проблема только с modal
.
Контроллер
public function dataProcessing(Request $request)
{
$columns = array(
0 => 'case_number',
1 => 'patient',
2 => 'name',
3 => 'created_at',
4 => 'action'
);
$totalData = PrimaryCaseNo::count();
$limit = $request->input('length');
$start = $request->input('start');
$order = $columns[$request->input('order.0.column')];
$dir = $request->input('order.0.dir');
if (empty($request->input('search.value'))) {
$posts = PrimaryCaseNo::offset($start)
->limit($limit)
->orderBy($order, $dir)
->get();
$totalFiltered = PrimaryCaseNo::count();
} else {
$search = $request->input('search.value');
$posts = PrimaryCaseNo::where('patient', 'like', "%{$search}%")
->orWhere('case_number', 'like', "%{$search}%")
->orWhere('created_at', 'like', "%{$search}%")
->offset($start)
->limit($limit)
->orderBy($order, $dir)
->get();
$totalFiltered = PrimaryCaseNo::where('patient', 'like', "%{$search}%")
->orWhere('case_number', 'like', "%{$search}%")
->count();
}
$data = array();
if ($posts) {
foreach ($posts as $r) {
$nestedData['case_number'] = $r->case_number;
$nestedData['patient'] = $r->patient;
$nestedData['created_at'] = Carbon::createFromTimeStamp(strtotime($r->created_at))->isoFormat('MMM Do YY');
$nestedData['action'] = '
<a href="#!" class="btn btn-warning btn-xs">Edit</a>
<a id="' . $r->id . '" class="btn btn-default impression-case-list" data-toggle="modal" data-backdrop="static" data-target=".bd-example-modal-xl"data-keyboard="false"><i class="fa fa-fw fa-list" aria-hidden="true"></i></a>
';
$data[] = $nestedData;
}
}
$json_data = array(
"draw" => intval($request->input('draw')),
"recordsTotal" => intval($totalData),
"recordsFiltered" => intval($totalFiltered),
"data" => $data
);
echo json_encode($json_data);
}
Просмотр
@extends('layout')
@section('content')
<!-- Content Header (Page header) -->
<section class="content-header">
<h1>
<i class="fa fa-medkit"></i>
Case Stages
</h1>
<ol class="breadcrumb">
<li><a href="#"><i class="fa fa-dashboard"></i> Home</a></li>
<li><a href="#">Forms</a></li>
<li class="active">General Elements</li>
</ol>
</section>
<section class="content">
@include('company.case_stages')
<div class="box">
<div class="box-header">
<h3 class="box-title">Impression Case List</h3>
</div>
<!-- /.box-header -->
<div class="box-body">
<table id="example1" class="table table-bordered table-striped">
<thead>
<tr role="row">
<th>Case Number</th>
<th>Patient Name</th>
{{-- <th>Operator</th>--}}
<th>Case Registered</th>
<th>Actions</th>
</tr>
</thead>
<tbody>
</tbody>
</table>
</div>
<!-- /.box-body -->
</div>
<div class="modal fade bd-example-modal-xl" tabindex="-1" role="dialog" aria-labelledby="myExtraLargeModalLabel"
aria-hidden="true">
<div class="modal-dialog modal-xl">
<div class="modal-content">
<div id="casesList"></div>
<div class="modal-footer">
<button type="button" class="btn btn-default pull-left" data-dismiss="modal">Close</button>
<button type="button" class="btn btn-primary">Save changes</button>
</div>
</div>
<!-- /.modal-content -->
</div>
<!-- /.modal-dialog -->
</div>
<!-- /.modal -->
</section>
@endsection
@section('script')
@section('script')
<script>
$.ajaxSetup({
headers: {
'X-CSRF-TOKEN': $('meta[name="csrf-token"]').attr('content')
}
});
</script>
<script>
$('#example1').DataTable({
"processing": true,
"serverSide": true,
"ajax": {
"url": "<?= route('dataProcessing') ?>",
"dataType": "json",
"type": "POST",
"data": {"_token": "<?= csrf_token() ?>"}
},
"columns": [
{"data": "case_number"},
{"data": "patient"},
// {"data": "patient"},
{"data": "created_at"},
{"data": "action", "searchable": false, "orderable": false}
]
});
</script>
<script>
$('a').on('click', '.impression-case-list', function () {
alert('hi');
var id = $(this).attr('id');
$.ajax({
url: "{{route('show-impression-case-list-ajax-call')}}",
method: "POST",
data: {
"_token": "{{ csrf_token() }}",
id: id
},
success: function (data) {
// console.log(data.html);
// $('#caseNumberList').fadeIn();
$('#casesList').html(data.html);
}
});
});
</script>
@endsection
@endsection