mercredi 23 janvier 2019

Laravel DataTables multiple select with checkboxes

I am developing an application in Laravel with DataTables where i display data form Mysql database. How to do multiple selection with line color for each selection ? like this link but with multiple selection and how to get values from the selected line ?

This is a screenshot of the app:

enter image description here

Here is code:

$(document).ready(function() {
 $('#pdr_table').DataTable({
    "processing": true,
    "serverSide": true,
    "ajax": "",
    "columns":[
        { "data": "checkbox", orderable:false, searchable:false},
        { "data": "ID_Piece" },
        { "data": "Designation" },
        { "data": "Status" },
        { "data": "action"}
    ],
    //"order": [[ 0, "asc" ]],
    'rowCallback': function(row, data, index){ 
        if(data.Status == 'Disponible'){ 
            $(row).find('td:eq(3)').css('background-color', 'green').css('color', 'white'); 
        }
        if(data.Status == 'Indisponible'){ 
            $(row).find('td:eq(3)').css('background-color', 'red').css('color', 'white'); 
        } 
    }
 });    

$(document).on('click', '.Ajouter_au_panier', function(){
    $('#pdrModal').modal('show');
    $('#pdr_form')[0].reset();
    $('#form_output').html('');
    $('#piece').text('PDR'); 
});

$('#pdr_form').on('submit', function(event){
    event.preventDefault();
    var form_data = $(this).serialize();
    $.ajax({
        url:"",
        method:"get",
        data:form_data,
        dataType:"json",
        success:function(data)
        {
            if(data.error.length > 0)
            {
                var error_html = '';
                for(var count = 0; count < data.error.length; count++)
                {
                    error_html += '<div class="alert alert-danger">'+data.error[count]+'</div>';
                }
                $('#form_output').html(error_html);
            }
            else
            {                            
                $('#form_output').html(data.success);
                $('#pdr_form')[0].reset();
                $('#pdr_table').DataTable().ajax.reload();
            }
        }
    })
});




Aucun commentaire:

Enregistrer un commentaire