KoolReport's Forum

Official Support Area, Q&As, Discussions, Suggestions and Bug reports.
Forum's Guidelines

Server Processing Search bar configuration #2172

Open Niall McGuirk opened this topic on on Jun 30, 2021 - 7 comments

Niall McGuirk commented on Jun 30, 2021

I'm trying to setup a report which shows a table, which enables you to search by only 1 specified column in the database table. I'm using Server Processing, as the DB table contains 6 million rows. Currently I'm using the built in Search box which appears when using the Server Processing table from the Kool Report examples page, however the problem is this uses the input to searches all columns, not just one specified column.

Is there a way to configure the search box to only use one Table Column? If there isn't, how to do connect my input box to the existing searching method?

Below is the code for generating the Server Processing table.

<?php
    use \koolreport\core\Utility as Util;
    use \koolreport\datagrid\DataTables;
?>
<style>
    .dataTables_paginate.paging_input {
        padding: 0 !important;
    }
    .dataTables_info,
    .dataTables_paginate.paging_input span,
    .dataTables_length label,
    .dataTables_filter label {
        padding-top: 5px !important;
        padding-bottom: 5px !important;
    }
    .dataTables_length label,
    .dataTables_filter label {
        margin: 0 20px !important;
    }
</style>
<div class="report-content">
    <div class="text-center">
        <h1>Summary of Councils</h1>
        <p class="lead">
            Summary of Councils using Server Processing
        </p>
    </div>

    <i class="fa fa-arrow-down" style="font-size:24px;"></i>
    <div style="margin-top:20px;">

    <?php
    DataTables::create(array(
        'name' => 'DataTable1',
        'dataSource' => function() {
            return $this->src('delv')
            ->query(' 
			SELECT 
    tblsourcesupplier.DelvRef,
    tblsourcetype.SourceType,
    tblsupplierinvoice.TotalInvoiceAmount,
    (tblsupplierinvoice.TotalInvoiceAmount) + (tblsupplierinvoice.Penalty) + (tblsupplierinvoice.Interest) AS ClaimValue,
    YEAR(paymentdate) AS PaymentYear
FROM
    Delv.tblsupplierinvoice
        INNER JOIN
    tblsourcesupplier ON tblsourcesupplier.ID = tblsupplierinvoice.SupplierID
        LEFT OUTER JOIN
    tblsource ON tblsource.id = tblsourcesupplier.sourceid
        LEFT OUTER JOIN
    tblsourcelocation ON tblsourcelocation.id = tblsource.locationid
        LEFT OUTER JOIN
    tblsourcetype ON tblsourcetype.ID = tblsource.SourceType
WHERE
    PaymentDate >= "2015-04-01"
        AND PaymentDate < DATE_ADD(CURDATE(), INTERVAL - 1 YEAR)
        AND TimetoPayInvoice > 30
		
 ');
            // ->query("select concat(e.first_name, ' ', e.last_name) as emp_name,
            // s.* from salaries s left join employees e on s.emp_no = e.emp_no");
        },
        'scope' => $this->params,
        "options" => array(
            "searching" => true,
            "paging" => true,
            "colReorder" => true,
            "order" => [],
            "ordering" => false,
            "pageLength" => 25,
            "pagingType" => "input",
            "dom" => '<"top"ipfl<"clear">>rt<"bottom"ipfl<"clear">>'
            // "dom" => '<"top"iflp<"clear">>rt<"bottom"ip<"clear">>'
        ),
        // "columns"=>array(
        //     "customerName" => array("label" => "Customer"),
        //     "productLine" => array("label" => "Category"),
        //     "productName" => array("label" => "Product"),
        // ),
        "showFooter"=>true,
        "serverSide"=>true,
        // "method"=>'post', //default method = 'get',
		"searchOnEnter" => true,
        "searchMode" => "or"
    ));
	
    ?>
</div>
Sebastian Morales commented on Jun 30, 2021

Hi, in the next version of Datagrid package, DataTables widget's server-side mode will have the option to search on server-side only "searchable" columns like this:

    DataTables::create(array(
        ...
        "options" => array(
            "columnDefs" => array(
                array( "targets" => [0, 1], "searchable" => true ), // Assuming you only want to search the 1st and 2nd columns. Higher columndef rules take priority over lower ones
                array( "targets" => '_all', "searchable" => false )
            )

or:

    DataTables::create(array(
        ...
        "columns" => array(
            "col1" => array( "label" => "Column 1", "searchable" => true ),
            "col2" => array( "label" => "Column 2", "searchable" => false ),

We are going to release the next version of KoolReport in the next few weeks. If you want to access this option earlier pls send us an email to support@koolreport.com. We would send you a development version of Datagrid for you to test it. Rgds,

Niall McGuirk commented on Jun 30, 2021

Thanks for the reply. I have emailed support@koolreport.com, and requested access to the development version.

In the meantime, do you know of any work around method of limiting the search to one column?

Sebastian Morales commented on Jun 30, 2021

We've sent you a link for the next version of Datagrid. Pls try it and let us know if there's any issue with the new searchable columns option. Tks,

Niall McGuirk commented on Jun 30, 2021

Hi, I've replaced the previous datagrid version. I've tried placing the code as you did above. However, I get an error. How do I correctly implement it?

Error: Parse error: syntax error, unexpected '"searching"' (T_CONSTANT_ENCAPSED_STRING), expecting ')' in C:\Apache24\htdocs\examples\reports\Niall\DelvSummaryOfCouncils\MyReport.view.php on line 69 Code:

<?php
    use \koolreport\core\Utility as Util;
    use \koolreport\datagrid\DataTables;
?>
<style>
    .dataTables_paginate.paging_input {
        padding: 0 !important;
    }
    .dataTables_info,
    .dataTables_paginate.paging_input span,
    .dataTables_length label,
    .dataTables_filter label {
        padding-top: 5px !important;
        padding-bottom: 5px !important;
    }
    .dataTables_length label,
    .dataTables_filter label {
        margin: 0 20px !important;
    }
</style>
<div class="report-content">
    <div class="text-center">
        <h1>Summary of Councils</h1>
        <p class="lead">
            Summary of Councils using Server Processing
        </p>
    </div>

    <i class="fa fa-arrow-down" style="font-size:24px;"></i>
    <div style="margin-top:20px;">

    <?php
    DataTables::create(array(
        'name' => 'DataTable1',
        'dataSource' => function() {
            return $this->src('delv')
            ->query(' 
			SELECT 
    tblsourcesupplier.DelvRef,
    tblsourcetype.SourceType,
    tblsupplierinvoice.TotalInvoiceAmount,
    (tblsupplierinvoice.TotalInvoiceAmount) + (tblsupplierinvoice.Penalty) + (tblsupplierinvoice.Interest) AS ClaimValue,
    YEAR(paymentdate) AS PaymentYear
FROM
    Delv.tblsupplierinvoice
        INNER JOIN
    tblsourcesupplier ON tblsourcesupplier.ID = tblsupplierinvoice.SupplierID
        LEFT OUTER JOIN
    tblsource ON tblsource.id = tblsourcesupplier.sourceid
        LEFT OUTER JOIN
    tblsourcelocation ON tblsourcelocation.id = tblsource.locationid
        LEFT OUTER JOIN
    tblsourcetype ON tblsourcetype.ID = tblsource.SourceType
WHERE
    PaymentDate >= "2015-04-01"
        AND PaymentDate < DATE_ADD(CURDATE(), INTERVAL - 1 YEAR)
        AND TimetoPayInvoice > 30
		
 ');
            // ->query("select concat(e.first_name, ' ', e.last_name) as emp_name,
            // s.* from salaries s left join employees e on s.emp_no = e.emp_no");
        },
        'scope' => $this->params,
        "options" => array(
		"columnDefs" => array(
                array( "targets" => [0, 1], "searchable" => true ), // Assuming you only want to search the 1st and 2nd columns. Higher columndef rules take priority over lower ones
                array( "targets" => '_all', "searchable" => false ),
            )
            "searching" => true, //this is line 69, where the error took place
            "paging" => true,
            "colReorder" => true,
            "order" => [],
            "ordering" => false,
            "pageLength" => 25,
            "pagingType" => "input",
            "dom" => '<"top"ipfl<"clear">>rt<"bottom"ipfl<"clear">>'
            // "dom" => '<"top"iflp<"clear">>rt<"bottom"ip<"clear">>'
        ),
        // "columns"=>array(
        //     "customerName" => array("label" => "Customer"),
        //     "productLine" => array("label" => "Category"),
        //     "productName" => array("label" => "Product"),
        // ),
        "showFooter"=>true,
        "serverSide"=>true,
        // "method"=>'post', //default method = 'get',
		"searchOnEnter" => true,
        "searchMode" => "or"
    ));
	
    ?>
</div>
Niall McGuirk commented on Jun 30, 2021

Disregard previous. It was a misplaced comma.

Niall McGuirk commented on Jun 30, 2021

Hi, The searchable columns works fine, so far. Thanks for the help. However, is there an alternate SearchMode to "or", that searches for the exact value, as oppose to the search value being within? I need it to be "123", instead of "%123%". Does this exist in the DataGrid package?

Sebastian Morales commented on Jul 1, 2021

Ah, this is tricky with the current default or "OR" search mode. We will add a new search mode to make this possible for both server side and client side searching and let you know when it's available. Tks,

Build Your Excellent Data Report

Let KoolReport help you to make great reports. It's free & open-source released under MIT license.

Download KoolReport View demo
help needed
solved

DataGrid