PHP code example of tegansnyder / idiorm-datatable-json-bridge

1. Go to this page and download the library: Download tegansnyder/idiorm-datatable-json-bridge library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

tegansnyder / idiorm-datatable-json-bridge example snippets


$datatable_json = ORMDatatableBridge::for_table('products')
->where(
    [
        'name'	=> 'Test Product 1',
        'price'	=> 23
    ]
)
->get_datatable();

echo $datatable_json;

$datatable_json = ORMDatatableBridge::for_table('products')
->get_datatable(
	[
		'DT_RowId' => [
			'type' => 'dynamic',
			'key'  => 'products_'
		],
		'DT_RowData' => [
			'weight' => 'total_weight_{{weight}}',
			'price'  => '{{price}}'
		]
	]
);

$datatable_json = ORMDatatableBridge::for_table('products')
->where('id', 1)
->get_datatable(
	[
		'DT_RowId' => [
			'type' => 'dynamic',
			'key'  => 'id',
			'prepend' => 'id_'
		],
		'DT_RowData' => [
			'weight' => 'ship_weight_{{weight}}'
		],
		'dynamic_columns' => [
			[
				'key' => 'edit',
				'column_template' => '<a href="edit.php?id={id}}">Edit</a>'
			],
			[
				'key' => 'delete',
				'column_template' => '<a href="/delete.php?id={{id}}">Delete</a>'
			]
		],
		'wrap_columns' => [
			[
				'key' => 'id',
				'column_template' => '<a href="/view.php?id={{id}}">{{id}}</a>'
			],
			[
				'key' => 'name',
				'column_template' => '<a href="/view.php?id={{id}}">{{name}}</a>'
			]
		],
		'wrap_all' => [
            'columns' => '<section class="datatable-column {{col_name}}">{{column_data}}</section>'
		]
	]
);

$datatable_json = ORMDatatableBridge::for_table('products')
->select(
    [
        'name', 
        'id',
        'price'
    ]
)
->get_datatable(
    [
        'hide_columns' => [
            'id'
        ]
    ]
);

$datatable_json = ORMDatatableBridge::for_table('products')
->select(
    [
        'name', 
        'id',
        'price'
    ]
)
->get_datatable(
    [
        'hide_columns' => [
            'id'
        ],
        'wrap_columns' => [
            [
                'key' => 'id',
                'column_template' => '<a href="/product/view/{{id}}" target="_self">{{name}}</a>'
            ]
        ],
    ]
);

$datatable_json = ORMDatatableBridge::for_table('products')
->select(
    [
        'name', 
        'id',
        'price'
    ]
)
->get_datatable(
    [
        'hide_columns' => [
            'id'
        ],
        'just_columns' => true
    ]
);

$datatable_json = ORMDatatableBridge::for_table('products')
->select(
    [
        'name', 
        'id',
        'store_price'
    ]
)
->get_datatable(
    [
        'column_display_names' => [
            'name' => 'Name',
            'store_price' => 'Store Price'
        ]
    ]
);

$datatable_json = ORMDatatableBridge::for_table('products')
->select(
    [
        'name', 
        'id',
        'store_price'
    ]
)
->get_datatable(
    [
        'column_order' => [
            'store_price',
            'id',
            'name'
        ]
    ]
);
json
{
    "recordsTotal": 1,
    "recordsFiltered": 1,
    "data": [
        {
            "id": "<section class=\"datatable-column\"><a href=\"/view.php?id=1\">1</a></section>",
            "name": "<section class=\"datatable-column\"><a href=\"/view.php?id=<a href=\"/view.php?id=1\">1</a>\">Test Product 1</a></section>",
            "price": "<section class=\"datatable-column\">23</section>",
            "weight": "<section class=\"datatable-column\">12lbs</section>",
            "DT_RowId": "id_1",
            "DT_RowData": {
                "weight": "ship_weight_12lbs"
            },
            "edit": "<section class=\"datatable-column\"><a href=\"edit.php?id={id}}\">Edit</a></section>",
            "delete": "<section class=\"datatable-column\"><a href=\"/delete.php?id=1\">Delete</a></section>"
        }
    ]
}