search not working

search not working

lui1969lui1969 Posts: 7Questions: 0Answers: 0
edited May 2021 in DataTables 1.10

no link:
**$(document).ready(function(){

var itemRecords = $('#itemsListing').DataTable({
    "lengthChange": false,
    "processing":true,
    "serverSide":true,
    "bFilter": true,
    'serverMethod': 'post',
    "order":[],
    "ajax":{
        url:"items_action.php",
        type:"POST",
        data:{action:'listItems'},
        dataType:"json"
    },
    "columnDefs":[
        {
            "targets":[0, 5, 6],
            "orderable":false,
        },
    ],
    "pageLength": 10
});


$('#addItems').click(function(){
    $('#itemModal').modal({
        backdrop: 'static',
        keyboard: false
    });
    $("#itemModal").on("shown.bs.modal", function () {
        $('#itemForm')[0].reset();
        $('.modal-title').html("<i class='fa fa-plus'></i> Add Item");
        $('#action').val('addItem');
        $('#save').val('Save');
    });
});

$("#itemsListing").on('click', '.update', function(){
    var id = $(this).attr("id");
    var action = 'getItemDetails';
    $.ajax({
        url:'items_action.php',
        method:"POST",
        data:{id:id, action:action},
        dataType:"json",
        success:function(respData){
            $("#itemModal").on("shown.bs.modal", function () {
                $('#itemForm')[0].reset();
                respData.data.forEach(function(item){
                    $('#id').val(item['id']);
                    $('#itemName').val(item['item_name']);
                    $('#price').val(item['price']);
                    $('#itemCategory').val(item['category_id']);
                    $('#status').val(item['status']);
                });
                $('.modal-title').html("<i class='fa fa-plus'></i> Edit item");
                $('#action').val('updateItem');
                $('#save').val('Save');
            }).modal({
                backdrop: 'static',
                keyboard: false
            });
        }
    });
});

$("#itemModal").on('submit','#itemForm', function(event){
    event.preventDefault();
    $('#save').attr('disabled','disabled');
    var formData = $(this).serialize();
    $.ajax({
        url:"items_action.php",
        method:"POST",
        data:formData,
        success:function(data){
            $('#itemForm')[0].reset();
            $('#itemModal').modal('hide');
            $('#save').attr('disabled', false);
            itemRecords.ajax.reload();
        }
    })
});

$("#itemsListing").on('click', '.delete', function(){
    var id = $(this).attr("id");
    var action = "deleteItem";
    if(confirm("Are you sure you want to delete this record?")) {
        $.ajax({
            url:"items_action.php",
            method:"POST",
            data:{id:id, action:action},
            success:function(data) {
                itemRecords.ajax.reload();
            }
        })
    } else {
        return false;
    }
});

});**:
No error:
I apologize for my bad English, the problem I find is that the search function does not work I have been trying to understand the cause for days I have carried out many tests by reading the various answers but I can not find anything that works for me.:

Replies

  • kthorngrenkthorngren Posts: 20,300Questions: 26Answers: 4,769

    You are using server side processing (serverSide: true) which means your server script is responsible for searching, sort and paging. See the server side protocol docs. There are server side examples you can look at. The server side PHP script used in the examples is here.

    If you still need help please post a link to your page or a test case replicating the issue so we can help debug.
    https://datatables.net/manual/tech-notes/10#How-to-provide-a-test-case

    Kevin

  • lui1969lui1969 Posts: 7Questions: 0Answers: 0

    thanks for your kind response, in fact the problems I encounter are research and layout. I really need help

  • colincolin Posts: 15,143Questions: 1Answers: 2,586

    To progress this, as Kevin said, please post a link to a test case,

    Colin

  • lui1969lui1969 Posts: 7Questions: 0Answers: 0

    thanks http://pointscard.moeasy.it/rest/index.php
    email: sviluppo@moeasy.it
    password: Password-12-12-12

    Thanks for your support

  • lui1969lui1969 Posts: 7Questions: 0Answers: 0
    edited May 2021

    i modified the code by adding this lines

    "columns": [
                {"data": "name"},
                {"data": "price"},
                {"data": "category_id"},
                {"data": "status"}
            ],
    

    after

    "columnDefs": [
    {
    "targets": [0, 5, 6],
    "orderable": false,
    },
    ],
    

    also I have also entered this code

    <? php
    $ table = 'restaurant_items';
    // Table's primary key
    $ primaryKey = 'id';
    
    // Array of database columns which should be read and sent back to DataTables.
    // The `db` parameter represents the column name in the database, while the` dt`
    // parameter represents the DataTables column identifier. In this case object
    // parameter names
    $ columns = array (
        array ('db' => 'name', 'dt' => 'name'),
        array ('db' => 'price', 'dt' => 'price'),
        array ('db' => 'category_id', 'dt' => 'category_id'),
        array ('db' => 'status', 'dt' => 'status'),
    );
    $ sql_details = array (
        'user' => 'eesitola_ristora',
        'pass' => 'RestDoe1188HgrTTT',
        'db' => 'eesitola_ristora',
        'host' => 'localhost'
    );
    
    require ('ssp.class.php');
    
    echo json_encode (
        SSP :: simple ($ _GET, $ sql_details, $ table, $ primaryKey, $ columns)
    );
    ?>
    

    inside url: "items_action.php",
    and I have successfully created the ssp.class.php file inside the root

    what I see is a page with "processing ....."

    inspecting the code I get this error
    TypeError: undefined is not an object (evaluating 'n [m] .style')

    Edited by Colin - Syntax highlighting. Details on how to highlight code using markdown can be found in this guide.

  • colincolin Posts: 15,143Questions: 1Answers: 2,586

    It looks like you've got a space between the $ and your variable name - this would give a syntax error I believe. I'm not that familiar with PHP. Could you give those in the scripts, please, and see if that makes a difference,

    Colin

  • lui1969lui1969 Posts: 7Questions: 0Answers: 0

    thanks for your reply, what script do you want me to insert?

  • colincolin Posts: 15,143Questions: 1Answers: 2,586

    Sorry, I meant "fix those", not "give those". I think

    $ primaryKey = 'id';
    

    should be

    $primaryKey = 'id';
    

    note the space after the $. That should be fixed for all the variables.

    Colin

  • lui1969lui1969 Posts: 7Questions: 0Answers: 0

    ok that was a copy and paste problem, it's correct in my code
    $primaryKey = 'id';

  • allanallan Posts: 61,714Questions: 1Answers: 10,103 Site admin

    You've got: type:"POST", but are using SSP :: simple ($ _GET.

    All of the information DataTables is sending to the server will be available under $_POST, not $_GET. I'd suggest changing that.

    Also remove the serverMethod option. I don't think it will override your type option in the ajax object, but it is redundant, so remove it.

    Allan

  • lui1969lui1969 Posts: 7Questions: 0Answers: 0

    thanks for your reply i have edited as you described, but i get this error message

    DataTables warning: table id=itemsListing - Invalid JSON response. For more information about this error, please see http://datatables.net/tn/1

    this code
    ('''

    Id Item Name Price Category Status
    <div id="itemModal" class="modal fade">
        <div class="modal-dialog">
            <form method="post" id="itemForm">
                <div class="modal-content">
                    <div class="modal-header">
                        <button type="button" class="close" data-dismiss="modal">&times;</button>
                        <h4 class="modal-title"><i class="fa fa-plus"></i> Edit Items</h4>
                    </div>
                    <div class="modal-body">
                        <div class="form-group">
                            <div class="row">
                                <label class="col-md-4 text-right">Item Name <span class="text-danger">*</span></label>
                                <div class="col-md-8">
                                    <input type="text" name="itemName" id="itemName" autocomplete="off" class="form-control" required />
                                </div>
                            </div>
                        </div>
    
                        <div class="form-group">
                            <div class="row">
                                <label class="col-md-4 text-right">Price <span class="text-danger">*</span></label>
                                <div class="col-md-8">
                                    <input type="text" name="price" id="price" autocomplete="off" class="form-control" required />
                                </div>
                            </div>
                        </div>
    
                        <div class="form-group">
                            <div class="row">
                                <label class="col-md-4 text-right">Item Category <span class="text-danger">*</span></label>
                                <div class="col-md-8">
                                    <select name="itemCategory" id="itemCategory" class="form-control">
                                        <?php
                                        $categoryResult = $item->getItemCategory();
                                        while ($category = $categoryResult->fetch_assoc()) {
                                        ?>
                                            <option value="<?php echo $category['id']; ?>"><?php echo $category['name']; ?></option>
                                        <?php } ?>
                                    </select>
                                </div>
                            </div>
                        </div>
    
                        <div class="form-group">
                            <div class="row">
                                <label class="col-md-4 text-right">Status <span class="text-danger">*</span></label>
                                <div class="col-md-8">
                                    <select name="status" id="status" class="form-control">
                                        <option value="Enable">Enable</option>
                                        <option value="Disable">Disable</option>
                                    </select>
                                </div>
                            </div>
                        </div>
                    </div>
                    <div class="modal-footer">
                        <input type="hidden" name="id" id="id" />
                        <input type="hidden" name="action" id="action" value="" />
                        <input type="submit" name="save" id="save" class="btn btn-info" value="Save" />
                        <button type="button" class="btn btn-default" data-dismiss="modal">Close</button>
                    </div>
                </div>
            </form>
        </div>
    </div>
    

    ''')

  • kthorngrenkthorngren Posts: 20,300Questions: 26Answers: 4,769

    Have you followed the troubleshooting steps found in the technote?
    http://datatables.net/tn/1

    Let us know what you find.

    Kevin

This discussion has been closed.