Modal server side filter
Modal server side filter
Alex2019
Posts: 62Questions: 9Answers: 0
Hello everyone
I have this code to view a drop -down box to filter the results (Yes)
This code works in another code (it is filtered correctly) but now I have inserted more code with MODAL function to add/edit and delete (crud) and the previous code does not work
These are the lines I added to index.php
load_data();
function load_data(is_incollection)
{
...........
data:{is_incollection:is_incollection}
...........
$(document).on('change', '#incoll_yes', function(){
var incoll_yes = $(this).val();
$('#user_data').DataTable().destroy();
if(incoll_yes != '')
{
load_data(incoll_yes);
}
else
{
load_data();
}
});
Obviously also in the ajax fetch.php code it is present isset
if(isset($_POST["is_incollection"]))
{
$query .= "incollection = '".$_POST["is_incollection"]."' AND ";
}
I display the drop -down box but the results are empty
code complete
<script type="text/javascript" language="javascript" >
$(document).ready(function(){
$('#add_button').click(function(){
$('#user_form')[0].reset();
$('.modal-title').text("Add User");
$('#action').val("Add");
$('#operation').val("Add");
});
load_data();
function load_data(is_incollection)
{
var dataTable = $('#user_data').DataTable({
"processing":true,
"serverSide":true,
"order": [[ 0, "desc" ]],
"pageLength": 5,
"lengthChange": false, // Will Disabled Record number per page
"dom": 'lfirtip',
"language": {
"processing": 'Please wait - loading...' //oppure circle '<i class="fa fa-spinner fa-spin fa-2x fa-fw"></i>'
},
"ajax":{
url:"fetch.php",
type:"POST",
data:{is_incollection:is_incollection}
},
"columnDefs":[
{
"targets":[6,7 ],
"orderable":false
}
]
});
}
//
$(document).on('change', '#incoll_yes', function(){
var incoll_yes = $(this).val();
$('#user_data').DataTable().destroy();
if(incoll_yes != '')
{
load_data(incoll_yes);
}
else
{
load_data();
}
});
///
$(document).on('submit', '#user_form', function(event){
event.preventDefault();
var title = $('#title').val();
var cast = $('#cast').val();
if(title != '' && cast != '')
{
$.ajax({
url:"insert.php",
method:'POST',
data:new FormData(this),
contentType:false,
processData:false,
success:function(data)
{
alert(data);
$('#user_form')[0].reset();
$('#userModal').modal('hide');
dataTable.ajax.reload();
}
});
}
else
{
alert("Both Fields are Required");
}
});
$(document).on('click', '.update', function(){
var id = $(this).attr("id");
$.ajax({
url:"update.php",
method:"POST",
data:{id:id},
dataType:"json",
success:function(data)
{
$('#userModal').modal('show');
$('#title').val(data.title);
$('#data_production').val(data.data_production);
$('#incollection').val(data.incollection);
$('#trailer').val(data.trailer);
$('#duration').val(data.duration);
$('#dimvideo').val(data.dimvideo);
$('.modal-title').text("Edit User");
$('#id').val(id);
$('#action').val("Edit");
$('#operation').val("Edit");
}
})
});
$(document).on('click', '.delete', function(){
var id = $(this).attr("id");
if(confirm("Are you sure you want to delete this?"))
{
$.ajax({
url:"delete.php",
method:"POST",
data:{id:id},
success:function(data)
{
alert(data);
dataTable.ajax.reload();
}
});
}
else
{
return false;
}
});
});
</script>
Replies
Can you link to a page showing the issue please? That makes it much more tractable to debug.
Allan