Monday, November 20, 2017

Getting the index of a table column by TH name

The Table HTML:
<table class="table table-bordered table-hover" id="table">
    <thead>
    <tr>
        <th class="text-center">Name</th>
        <th class="text-center">Phone number</th>
        <th class="text-center">Action</th>
        <th class="text-center">Message</th>
        <th class="text-center">Date</th>
        <th class="text-center">Actions</th>
    </tr>
    </thead>
    <tbody>
    </tbody>
</table>
Here's how to get the index of the "Date" column:
var idx = $('#table th:contains("Date")').index();

Get row data from Datatables

You know how you'll have a action item on every row of your Datatable and need to get that row data when that item is clicked?



Here's how:

//
// create datatable
//
var table = $('#table').DataTable({
    ...
    ...
});

//
// handle clicks of the action selector
//
$('.action-selector').click(function(ev){
    var rowdata = table.row( $(this).parents('tr') ).data();
    //
    // rowdata now has the data from the row that 'action-selector' was clicked on
    //
}

Wednesday, November 8, 2017

Twilio 502 gateway errors when using Valet / ngrok.io

Are you getting 502 gateway errors when using Valet / ngrok.io with Twilio? Update your ngrok.io and it should fix it (press control-u while ngrok.io is running, then restart it).