Friday, 24 April 2015

Simple example of datatables

Today's post is about use of datatables. Lot of examples are available on Internet. This example is just to explore it little more and explains how to read data from xml and display using datatables.


$file_content = file_get_contents($file_url);

//Optional: Start of code if you want to add some attribute to xml
//code to add unique_id attribute
/*foreach( $xml_string_arr->xpath("entry") as $r ) {
    $attrs = $r->attributes();   
        $r->addAttribute('unique_id', $r->id);
//End of code if you want to add some attribute to xml

$json = json_encode($xml_string_arr);
$arr_new = json_decode($json,TRUE);

$required_content_arr = $arr_new['entry'];

<!DOCTYPE html>
    <link rel="stylesheet" href="DataTables/media/css/jquery.dataTables.css">
    <script src="DataTables/media/js/jquery.js"></script>
    <script src="DataTables/media/js/jquery.dataTables.js"></script>

  <table id="example" class="display" cellspacing="0" width="100%">

<script language="javascript"> 
    $(document).ready(function() {
        var oTable = $('#example').dataTable({
            data: <?php echo json_encode($required_content_arr); ?>,
            columns: [
                { data: 'id' },
                { data: 'name' },
                { data: 'url' },
                { data: 'height' },               
    } );   

Thanks!!!!!!!!!! Enjoy Programming :)

No comments:

Post a Comment

Thanks for your valuable comments.

Odoo 10: Close wizard and open standard form

Hi, Today we are going to learn how to open standard form after saving data in wizard. Let's say I have created an wizard to fill bas...