KoolReport's Forum

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

Updating datatable widget labels #1813

Open Ron opened this topic on on Dec 31, 2020 - 4 comments

Ron commented on Dec 31, 2020

Hi

I am using the DataTable widget with the following option enabled:

DataTables::create(array(
            "dataSource"=>$this->dataStore("st"),
            "fastRender" => true,
            "options"=>array(
                "colReorder"=>true,
                "searching"=>true,
                "paging"=>true,
                "pageLength" => 10,
                "orders"=>array(
                    array(1,"asc")
                ),
                'columnDefs' => array(
                    array(
        				'visible' => false,
        				//'targets' => [$this->monthDays+6], //hide the first column
        			)
        		),
            ),
            'complexHeaders' => true,
            'headerSeparator' => ' - ',
            'cssClass'=>array(
                'table'=>'table table-bordered',
                'tr'=>'cssItem',
                'td'=>function($row,$colName)
                {
                    return in_array($colName, array('teacher_id','id_number', 'reason')) ? 'text-right' : 'text-center';
                },
                'th'=>function($colName)
                {
                    return in_array($colName, array('teacher_id','id_number','reason')) ? 'table-dark text-right' : 'table-dark text-center';
                },
            ),
        ));

I need the ability to do the following: 1. To update the next/previous labels in the paging. 2. To update the search input label 3. Showing 1 to ... I want to change the labels. 4. When I print the report I need that the search input and the number of entries will not appear. 5. Sorting is not working for column number 1. by default the first column is sorted and I can not cancel it.

Thanks

Ron commented on Dec 31, 2020

here is the screen capture

David Winterburn commented on Jan 4, 2021

To answer your multiple questions:

1 . Use DataTables' paging event:

https://datatables.net/reference/event/page

Just add a script tag at the end of report view and replace $('#example') with the id/name of DataTables widget.

2 . Use the search event the same as the paging event:

https://datatables.net/reference/event/search

3 . We don't get your question clearly.

4 . Use the search event to cliently update a label in your report view with the number of rows by count method:

https://datatables.net/reference/api/count()

5 . To disable initial sorting:

DataTables::create(array(
    ...
    "options" => array(
        "order" => [],
    ),
));
Ron commented on Jan 4, 2021

Hi David, 1. Disabling sorting with the code you supplied does not work. it still does the sorting for the first column.

DataTables::create(array(
            "dataSource"=>$this->dataStore("st"),
            "fastRender" => true,
            "options"=>array(
                "colReorder"=>true,
                "searching"=>true,
                "paging"=>true,
                "pageLength" => 10,
                "orders"=>[],
                'columnDefs' => array(
                    array(
        				'visible' => false,
        				//'targets' => [$this->monthDays+6], //hide the first column
        			)
        		),
            ),
            'complexHeaders' => true,
            'headerSeparator' => ' - ',
            'cssClass'=>array(
                'table'=>'table table-bordered',
                'tr'=>'cssItem',
                'td'=>function($row,$colName)
                {
                    return in_array($colName, array('teacher_id','id_number', 'reason')) ? 'text-right' : 'text-center';
                },
                'th'=>function($colName)
                {
                    return in_array($colName, array('teacher_id','id_number','reason')) ? 'table-dark text-right' : 'table-dark text-center';
                },
            ),
        ));
        echo '<div class="footer print-only">Footer</div>';
  1. In case I want to use the Datatable paging event I need to know the table id. as I understand it is generated dynamically by the PHP. how can I get/set it?

  2. In the bottom os the datatable there is a label that says "Showing 1 to 10 of x entities (filtered from 100 entities). I want to change the label language

David Winterburn commented on Jan 5, 2021

1 . The property is "order" => [], not "orders" => [].

2 . The DataTables id is the name property when you create it in PHP:

<?php
    DataTables::create(array(
        "name" => "myTable",
        ...
    ));
?>
<script>
    myTable.on( 'page.dt', function () {
        ...
</script>

3 . There are multiple language files in `koolreport/datagrid/languages' directory. You could set DataTables' language like this:

    DataTables::create(array(
        ...
        "language" => "de", //use 'DataTables.de.json'
    ));

If no language file match yours just copy and modify one.

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
None yet

None