HTML Output (Run Time: 0.0004s)

<div class="jarviswidget" id="widget-id" data-widget-editbutton="false">
    <header>
        <span class="widget-icon"> <i class="fa fa fa-exclamation"></i> </span>
        <div class="widget-toolbar" id="" >
            <div class="btn-group">
                <button class="btn btn-primary dropdown-toggle" data-toggle="dropdown">
Filter Cities <span class="caret"></span>
</button>
                <ul class="dropdown-menu">
                    <li>
                        <a href="#">
                            <div class="checkbox">
                                <label>
                                    <input type="checkbox" value="Fogo" class="checkbox style-0" data-status-filter="Fogo" value="Fogo">
                                    <span>Fogo</span>

                                </label>
                            </div>
                        </a>
                    </li>
                    <li>
                        <a href="#">
                            <div class="checkbox">
                                <label>
                                    <input type="checkbox" value="Machelen" class="checkbox style-0" data-status-filter="Machelen" value="Machelen">
                                    <span>Machelen</span>

                                </label>
                            </div>
                        </a>
                    </li>
                    <li>
                        <a href="#">
                            <div class="checkbox">
                                <label>
                                    <input type="checkbox" value="Norman" class="checkbox style-0" data-status-filter="Norman" value="Norman">
                                    <span>Norman</span>

                                </label>
                            </div>
                        </a>
                    </li>
                    <li>
                        <a href="#">
                            <div class="checkbox">
                                <label>
                                    <input type="checkbox" value="Kapolei" class="checkbox style-0" data-status-filter="Kapolei" value="Kapolei">
                                    <span>Kapolei</span>

                                </label>
                            </div>
                        </a>
                    </li>
                </ul>
            </div>
        </div>
        <h2>
            DataTable Result Set
        </h2>
    </header>
    <div>
        <div class="jarviswidget-editbox">
            <input class="form-control" type="text">
            <span class="note"><i class="fa fa-check text-success"></i> Change title to update and save instantly!</span>
        </div>
        <div class="widget-body no-padding">
            <table id="test-table-id" class="table table-striped table-bordered table-hover">
                <thead>
                    <tr>
                        <th class="center" width="20px"></th>
                        <th class="center table-checkbox" width="20px">
                            <label class="checkbox-inline">
                                <input type="checkbox" class="checkbox style-0">
                                <span></span>

                            </label>
                        </th>
                        <th> No Data </th>
                        <th class="hidden"> ID # </th>
                    </tr>
                </thead>
                <tbody></tbody>
            </table>
        </div>
    </div>
</div>

JS Output

$(function() {

$(".desktop[data-rel='tooltip']").tooltip();
$(".phone[data-rel='tooltip']").tooltip({placement: tooltip_placement});
function tooltip_placement(context, source) {
var $source = $(source);
var $parent = $source.closest("table")
var off1 = $parent.offset();
var w1 = $parent.width();

var off2 = $source.offset();
var w2 = $source.width();

if( parseInt(off2.left) < parseInt(off1.left) + parseInt(w1 / 2) ) return "right";
return "left";
}

$("#test-table-id a i[data-toggle='row-detail']").on("click", function () {
var nTr = $(this).parents("tr")[0];
if ( oTable_dbf84d3682d2612f13ec0e600d5497f0.fnIsOpen(nTr) )
{
/* This row is already open - close it */
$(this).removeClass("fa-chevron-down").addClass("fa-chevron-right");
this.title = "Show Details";
oTable_dbf84d3682d2612f13ec0e600d5497f0.fnClose( nTr );
}
else
{
/* Open this row */
$(this).removeClass("fa-chevron-right").addClass("fa-chevron-down");
this.title = "Hide Details";
oTable_dbf84d3682d2612f13ec0e600d5497f0.fnOpen( nTr, fnFormatDetails(oTable_dbf84d3682d2612f13ec0e600d5497f0, nTr), "details" );
}
return false;
});
var oTable_dbf84d3682d2612f13ec0e600d5497f0 = $("#test-table-id").dataTable({
'fnCreatedRow' : function( nRow, aData, iDataIndex ) {
var cell = $("td:eq(7)", nRow);
var city = aData[7];
if ( city == "Abbotsford" || city == "Baranello" ) {
cell.html(city + ' <span class="label label-info">great city</span>');
}
}, 'sDom' : "<'dt-toolbar'<'col-xs-6'f><'col-xs-6'T>r>"+
"t"+
"<'dt-toolbar-footer'<'col-xs-6'i><'col-xs-6'p>>", 'oTableTools' : {
"aButtons": [
"copy",
"csv",
"xls",
{
"sExtends": "pdf",
"sTitle": "SmartAdmin_PDF",
"sPdfMessage": "SmartAdmin PDF Export",
"sPdfSize": "letter"
},
{
"sExtends": "print",
"sMessage": "Generated by SmartAdmin <i>(press Esc to close)</i>"
}
],
"sSwfPath": "js/plugin/datatables/swf/copy_csv_xls_pdf.swf"
},

aoColumns: [
{"bSortable": false},
{"bSortable": false},
null, null
],
aaSorting: [],

});

// remove pagination div row ? TO-DO

$("#test-table-id_cols li label input[type=checkbox]").on("click", function() {
fnShowHideCol($(this).data("column-toggle"), $(this).prop("checked"));
});

function fnShowHideCol(iCol, bVis) {
/* Get the DataTables object again - this is not a recreation, just a get of the object */
//var bVis = oTable_dbf84d3682d2612f13ec0e600d5497f0.fnSettings().aoColumns[iCol].bVisible;
oTable_dbf84d3682d2612f13ec0e600d5497f0.fnSetColumnVis(iCol, bVis);
}

function fnFormatDetails ( oTable_dbf84d3682d2612f13ec0e600d5497f0, nTr ) {
var aData = oTable_dbf84d3682d2612f13ec0e600d5497f0.fnGetData( nTr );
return ' <div class="alert alert-warning fade in"> <i class="fa-fw fa fa-warning"></i> <strong>Warning</strong> The ID for {{Name}} is #'+aData[3]+'. </div>';
}

$("#test-table-id th input:checkbox").on("click" , function(){
var that = this;
$(this).closest("table").find("tr > td input:checkbox").each(function(){
this.checked = that.checked;
//$(this).closest("tr").toggleClass("selected");
});
});



function getTypeFilters() {
var aSearchTypes = [];
$("input[data-status-filter]").each(function(index, value) {
if ($(this).prop("checked")) {
var city = $(this).val();
aSearchTypes.push(city);
}
})
return aSearchTypes;
}

$("input[data-status-filter]").on("click", function() {
var filters = getTypeFilters();
oTable_dbf84d3682d2612f13ec0e600d5497f0.fnFilter(filters.join("|"), 7, true, false);
})
});

SmartUI::DataTable Class

This is a basic usage of SmartUI's DataTable class. If you want to know more about the real HTML layout, click here

SmartUI::DataTable($data [, $options = array(), $title = '<h2>DataTable Result Set</h2>']);

Setup

$data = json_decode(file_get_contents(APP_URL."/data/data.json"));

$ui = new SmartUI;
$options = array(
    'checkboxes' => true,
    'row_details' => '
        <div class="alert alert-warning fade in">
            <i class="fa-fw fa fa-warning"></i>
            <strong>Warning</strong> The ID for {{Name}} is #{{ID}}.
        </div>'
);

$dt = $ui->create_datatable($data, $options, '<h2>My Datatable</h2>');
);

Usage

// setup a cell
$dt->cell('Name', 
    array(
        'url' => 'http://myapp.com/?profile={{ID}}' // you get other's cell value using "{{COLUMN_NAME}}"
    )
);

$dt->cell('Name', function($row, $value) {
    return 'http://myapp.com/?profile='.$row->ID // or use a callback to return "Name" column's custom content
});

// hide a column
$dt->hide('City', true);
// or ...
$dt->hidden(array('City'));

Print HTML!

$dt->print_html();

Print JS!

<script>
    <?php
        $dt->print_js();
    ?>
</script>

Property Reference

Below are the list of available properties for the class:

DataTable::cell

array of specified column name with string, closure or array value

$cell = array(
    'COLUMN_NAME' => array(
        'icon' => '',
        'content' => '',
        'color' => '',
        'url' => array( // can also be a direct string URL
            'href' => '',
            'target' => '',
            'title' => '',
            'attr' => ''
        )
    )
);

// sample call
$dt->cell(
    "Phone" => '{{Name}} - {{Phone}} <span class="label label-success">active</span>'
);
// or..
$dt->cell('Phone', function($row, $value) {
    return $row->Name.' - '.$value.' <span class="label label-success">active</span>';
});

DataTable::col

array of specified column name with string, closure or array value

$col = array(
    'COLUMN_NAME' => array( // can also be a closure, but you need to return same array structure. If string, it's default to the 'name' key
        'name' => '',
        'class' => '',
        'attr' => '',
        'icon' => '',
        'hidden' => false // or true
    )
);

// sample call
$dt->col('ID', array(
    'name' => 'ID #'
));

// or...
$dt->col('ID', 'ID #');

DataTable::options

array of options.

$options = array(
    "in_widget" => true,
    "row_details" => false,
    "checkboxes" => false,
    "static" => false,
    "paginate" => true
);

// sample call
$dt->options('in_widget', true)->options('checkboxes', true);

DataTable::data

array of object or array. This is the main datasource. It's recomended to set this up upon $ui->create_datatable($data);

DataTable::widget

SmartUI::Widget the main widget container of the table (if $options['in_widget'] == true). Check out Widget Class documentation here

DataTable::id

string of table's id (will create a unique id if not specified)

DataTable::row

array array of specified row index with array, closure or string values.

$row = array(2, array(
    "hidden" => false,
    "checkbox" => true,
    "detail" => true,
    "class" => "",
    "attr" => "",
    "content" => true
));

// sample call
$dt->row(2, array(
    'checkbox' => false,
    'deail' => true
))
// empty a row
$dt->row(3, '');
//hide a row
$dt->row(4, false);

DataTable::hidden

array of hidden columns

// sample call
$dt->hidden(array('Name', 'Zip'));

DataTable::hide

array of column names with bool values

// sample call
$dt->hide('Name', true)->hide('Zip', true)->hide('City', false);

DataTable::js

array of js custom properties

$js = array(
    'properties' => array(),
    'oTable' => '', // the oTable var
    'custom' => ''
)

// sample call
$dt->js('properties', array(
    'fnCreatedRow' => 'function( nRow, aData, iDataIndex ) {
        var cell = $("td:eq(7)", nRow);
        var city = aData[7];
        if ( city == "Abbotsford" || city == "Baranello" ) {
            cell.html(city + \' <span class="label label-info">great city</span>\');
        }
    }'
));

DataTable::sort

array of specified coumn name to be sorted

$sort = array('COLUMN_NAME', 'asc');

// sample call
$dt->sort('Name', 'asc');