How to implement a filter on Yii 1.1 CGridView on data retrieved with join query

168 views Asked by At

I'm trying to implement a filter on an admin view using 'zii.widgets.grid.CGridView'.

As the title says, the data is retrieved by a query (a quite complex one, it has 6 left joins actually), and is given to the widget a CArrayDataProvider.

The problem is that the widget needs a class to implement the filter. Is there a simple way to implement the filter? Should I create a class only for this purpose?

I tryed what is sugested in this post, but no filter was displayed for me to know if works.

Thank you!

1

There are 1 answers

0
JPabloFuenzalida On BEST ANSWER

I found a work arround on this issue.

What I ended up doung was a javascript/jquery implementation of the filter, using datatables package.

<table class="table table-striped table-hover" id="extendedTable">
    <thead>
    <tr>
        <th>a_name</th>
        <th>b_name</th>
        <th>c_name</th>
    </tr>
    </thead>
    <tbody>
    <?php foreach ($myData as $data) { ?>
        <tr>
            <th><?php echo $data["a_name"]; ?></th>
            <th><?php echo $data["b_name"]; ?></th>
            <th><?php echo $data["c_name"]; ?></th>$data["g_id"]); ?></th>
        </tr>
    <?php
    } ?>
    </tbody>
</table>

<script>
    $(document).ready(function() {
        $('#extendedTable').DataTable(
            {
                dom: '<"clear">lfrtip',
                "paging": true,
                "ordering": true
            }
        );
    });
</script>

Where a, b, and c are the aliases for some tables and $myData is the array with the "extended model"'s instances.