Searching a rendered column

Searching a rendered column

baseball43v3rbaseball43v3r Posts: 11Questions: 3Answers: 0

I have a rendered column which is a concatenation of 3 previous columns, and I would like to be able to search that rendered column. the rendered result is in this format 00.000.00 but when I try and search using that format i get 0 results. How can I do this? For reference, this is my render code, and I have the 3 columns in the table but hidden to help with sorting.

data: null,
render: function(data, type, row) {
      return row.Product_Category + "." + row.Product_Number1 + "." + row.Product_Number2;        
}

This question has an accepted answers - jump to answer

Answers

  • allanallan Posts: 63,822Questions: 1Answers: 10,517 Site admin

    How are you searching? The built in search should work as expected. If it isn't, we'd need a test case.

    Allan

  • baseball43v3rbaseball43v3r Posts: 11Questions: 3Answers: 0

    I'm just using the built in search, it'll search the first two numbers but as soon as i type a period I get zero results. What can i provide that would be a meaningful test case?

  • baseball43v3rbaseball43v3r Posts: 11Questions: 3Answers: 0

    here is my javascript

    $(document).ready(function() {
                $('#dt').DataTable({
                    "processing": true,
                    "serverSide": true,
                    "ajax": "../dist/scripts/getProducts.php",
                    "columns": [
                        {
                            data: "Product_Category",
                            visible: false
                        },
                        {
                            data:"Product_Number1",
                            visible: false
                        },
                        {   data: "Product_Number2",
                            visible: false
                        },
                        {
                        data: null,
                        render: function(data, type, row) {
                            return row.Product_Category + "." + row.Product_Number1 + "." + row.Product_Number2;        
                        },
                        width: "5%"    
                    }, {
                        "data": "Name",
                        width: "40%" 
                    }, {
                        "data": "Price",
                        render: $.fn.dataTable.render.number(',', '.', 2, '$'),
                        width: "5%"
                    }, {
                        "data": "Desc_Short",
                        width: "50%"
                    }],
                    columnDefs: [ {
                    targets: [ 3 ],
                    orderData: [ 0,1,2 ]
                    } ]
                });
            });
    

    and here is an example of my json

    {
        "draw": 1,
        "recordsTotal": 3,
        "recordsFiltered": 3,
        "data": [
            {
                "Product_Category": "01",
                "Product_Number1": "100",
                "Product_Number2": "01",
                "Name": "Product A",
                "Price": "25.00",
                "Desc_Short": "",
                "Desc_Long": null,
                "Notes": null
            },
            {
                "Product_Category": "01",
                "Product_Number1": "381",
                "Product_Number2": "90",
                "Name": "Product B",
                "Price": "50.00",
                "Desc_Short": "",
                "Desc_Long": null,
                "Notes": null
            },
            {
                "Product_Category": "03",
                "Product_Number1": "150",
                "Product_Number2": "90",
                "Name": "Product C",
                "Price": "100.00",
                "Desc_Short": "",
                "Desc_Long": null,
                "Notes": null
            }
        ]
    }
    

    and here is my table

    <div class="dataTable_wrapper">
        <table class="table table-striped table-bordered table-hover" id="dt">
            <thead>
                <tr>
                    <th>Product Category</th>
                    <th>Product Number1</th>
                    <th>Product Number2</th>
                    <th>Product Number</th>
                    <th>Name</th>
                    <th>Price</th>
                    <th>Description</th>                                       
    
                </tr>
            </thead>
            <tfoot>
                <tr>
                    <th>Product Category</th>
                    <th>Product Number1</th>
                    <th>Product Number2</th>
                    <th>Product Number</th>
                    <th>Name</th>
                    <th>Price</th>
                    <th>Description</th>                                         
    
                </tr>
            </tfoot>
        </table>
    </div>
    
  • allanallan Posts: 63,822Questions: 1Answers: 10,517 Site admin
    Answer ✓

    "serverSide": true,

    Filtering is being done at the server-side if you have server-side processing enabled. Any issue with the filtering, therefore, is in the ../dist/scripts/getProducts.php script, whatever that is.

    Do you have tens of thousands of rows? You should only need server-side processing if that is the case.

    Allan

  • baseball43v3rbaseball43v3r Posts: 11Questions: 3Answers: 0

    Ah that explains a lot. removing that row makes it work as expected. Thank you for the explanation.

This discussion has been closed.