General developer forum

Key word search in table

 
Picture of Nilesh Pathade (eNyota Learning Pvt Ltd Pune)
Key word search in table
 

Hi All

I have create table using html_table() in moodle. 

There is basic code for html table.

$table = new html_table();
$table->head = array('Sr.No','Location Name', 'Address','Phone No','Email ID','Classroom','Actions');
$table->data[] = array($id, $location, $address, $phoneno,$emailid,$classroom_like,$link);
echo html_writer::table($table);

I want to create search box below the table and there should key words search. Can this possible.

Simply I am going to create search functionality of table records. 


Please help me.

 
Average of ratings: -
Picture of Nilesh Pathade (eNyota Learning Pvt Ltd Pune)
Re: Key word search in table
 

Yes I done it.

I used simple JQuery to search 

like :- 

$PAGE->requires->js( new moodle_url($CFG->wwwroot . '/course/format/classroom/jquery.min.js'));
$PAGE->requires->js( new moodle_url($CFG->wwwroot . '/course/format/classroom/search.js'));
$table->id = 'myTable';
$table->head = array('Classroom Name', 'Available Seats', 'Details', 'Equipment', 'Actions');
foreach ($results as $re) {
    if ($j >= 0) {
        $table->data[] = array($classroom, $seats, $details, $equipment, $link);
    }
    $j++;
}

JS FIle 

$(document).ready(function(){
    $("#search").on("keyup", function() {
        var value = $(this).val().toLowerCase();
        $("#myTable tbody tr").filter(function() {
            $(this).toggle($(this).text().toLowerCase().indexOf(value) > -1)
        });
    });
});
 
Average of ratings: -