mercredi 12 juin 2019

checkbox become unchecked after filtering the data after new view. how to stop checkbox from unchecked after data is filtered

I have a list of manufacturers in the sidebar from where when checkbox is checked data is filtered according to the manufacturers. but when view is load data is filtered but checkbox become unchecked. How can we stop checkbox to become unchecked after data is filtered.

working on laravel 5.1

Controller

      $productsFeatured = Product::select('products.id', 'products.name','products.low_emitting_material_prerequisite_file',
            'manufacturers.phone','manufacturers.address','manufacturers.linkedin_url','manufacturers.city', 'products.specs_file','products.specs_file_url','products.low_emitting_material_credit_file', 'products.logo', 'products.division_id', 'products.section_id', 'products.manufacturer_id', 'divisions.name as division_name', 'divisions.code as division_code', 'sections.name as section_name', 'sections.code')
                    ->whereIn('products.status', ['active'])
                    ->where(function ($query) {
                        $query->where('products.low_emitting_material_prerequisite_file', '!=', '');
                    })
                    ->where('users.user_type', 'manufacturer_paid')
                    ->leftJoin('products_selected_leeds', 'products.id', '=', 'products_selected_leeds.product_id')
                    ->leftJoin('sections', 'products.section_id', '=', 'sections.id')
                    ->leftJoin('divisions', 'products.division_id', '=', 'divisions.id')
                    ->join('manufacturers', 'products.manufacturer_id', '=', 'manufacturers.id')
                    ->join('users', 'manufacturers.user_id', '=', 'users.id')
                    ->orderBy('divisions.code', 'asc')
                    ->orderBy('sections.code', 'asc')
                    ->groupBy('products.id');

                    if($request->ajax() && $request->manufacturer){

                        $productsFeatured->whereIn('products.manufacturer_id', $request->manufacturer);
                        $productsFeatured = $productsFeatured->get();                     

                    } else{
                        $productsFeatured = $productsFeatured->get();
                    }


   if($request->ajax()){

                    return  view('guest::new_design_frontend.product-library')->with($productsFeatured); 

            }else{
                return  view('guest::new_design_frontend.product-library')->with($productsFeatured); 
            }

script

$(document).ready(function() {

        // filter_data();

        function filter_data() {

            var manufacturer = get_filter('manufacturer');
            $.ajax({   
                url: "",
                method: 'POST',
                headers: {
                        'X-CSRF-Token': $('meta[name="csrf-token"]').attr('content')
                    },
                data:{manufacturer:manufacturer} ,

                success:function(data){
                 $('body').html();

                    $('body').html(data);
                }
            });
        }
        function get_filter(class_name) {
            var filter = [];

            $('.'+class_name+':checked').each(function(){
            filter.push($(this).val());
        });
        return filter
        }
        $('.common_selector').click(function(){
        filter_data();
    });

    });

view

manufacturers as sidebar

 @foreach($manufacturers as $leedsManufacturer)
                                <div class="post" id="post">
                                    <label class=" my-checkbox gry2" id="manufacturer">
                                        <input type="checkbox" class="manufacturer common_selector" name="manufacturer[]" value="">
                                        <span class="checkmark"></span>
                                    </label>
                                </div>
                         @endforeach


checkbox is unchecked after filter the data whereas it should be not




Aucun commentaire:

Enregistrer un commentaire