src/hathoora/grid/grid.php
public static function renderGrid(&$arrGridData, $return = false)
    {
        $table_id = isset($arrGridData['table']['id']) ? $arrGridData['table']['id'] : 'htgrid_'. time() . rand(1,99999);
        $table_class = isset($arrGridData['table']['class']) ? $arrGridData['table']['class'] : null;
        $grid = $noResultsTableClass = $hasNoResults = null;

        $hathooraGridJS = '/_assets/_hathoora/hathooraGrid.js';
        if (!empty($arrGridData['javascript']['gridPluginURL']))
            $hathooraGridJS = $arrGridData['javascript']['gridPluginURL'];

        $gridHeader = $gridPager = $gridTable = $gridPager = null;
        $htmlAppend = isset($arrGridData['html']['append']) ? $arrGridData['html']['append'] : null;
        $table_id = $arrGridData['table']['id'];
        $onGridReadyCallBack = !empty($arrGridData['javascript']['onGridReadyCallBack']) ? $arrGridData['javascript']['onGridReadyCallBack'] : 'null';
        $ajaxCalls = isset($arrGridData['javascript']['ajax']) ? $arrGridData['javascript']['ajax'] : true;

        // pagination?
        if (empty($arrGridData['table']['pagination']))
            $arrGridData['table']['pagination'] = array('\hathoora\grid\pagination', 'simple');
        else if (is_string($arrGridData['table']['pagination']))
            $arrGridData['table']['pagination'] = array('\hathoora\grid\pagination', $arrGridData['table']['pagination']);
        
        if (isset($arrGridData['table']['template']))
            require($arrGridData['table']['template']);
        // load default template
        else
            require(__DIR__ .'/template.php');

        $gridPager = trim($gridPager);

        if (!empty($arrGridData['debug']))
            $htmlAppend .= '<br/><br/>' . $arrGridData['queryTotal'] . '<br/><br/>' . $arrGridData['queryRow'] . '<br/><pre>'. print_r($arrGridData, true) .'</pre>';

        // when not ajax call
        if (empty($arrGridData['pajax']))
        {
            $grid = $gridHeader .'
            <div id="'. $table_id .'_inner" htg-table_id="'. $table_id .'" class="hathooraGrid '. $table_class .' ' .$noResultsTableClass .'">';

            if ($ajaxCalls)
            {
                $grid .= '
                 <script type="text/javascript">
                    var hathooraGrid = hathooraGrid || {"tables": {}};
                    $(document).ready(function()
                    {
                        // load hathooraGrid if not already loaded
                        if (jQuery().hathooraGrid == undefined)
                        {
                            $.ajax({
                                url: "'. $hathooraGridJS .'",
                                dataType: "script",
                                async: false,
                                cache: true,
                                success: function(){}
                            });
                        }
                        
                        hathooraGrid["tables"]["'.$table_id.'"] = {
                                                                    "id":  "'. $table_id .'",
                                                                    "sort":  "'. $arrGridData['sort'] .'",
                                                                    "order":  "'. $arrGridData['order'] .'",
                                                                    "page": "'. $arrGridData['page'] .'",
                                                                    "url": "' . $arrGridData['table']['sort']['url'] .'",
                                                                    "limit": "'. $arrGridData['limit'] .'",
                                                                    "dynamic": "'. (!empty($arrGridData['table']['fields']['dynamic']) ? 1 : 0 ).'",
                                                                    "columns": '. (!empty($arrGridData['table']['columnsJS']) ? json_encode($arrGridData['table']['columnsJS']) : '{}') .'
                                                                }

                        $("#'. $table_id .'").hathooraGrid({"onReady": '. $onGridReadyCallBack .', "isHackReady": true});
                    });
                </script>';
            }

            $grid .=
                (!empty($arrGridData['table']['options']['topPager']) ? '<div class="hathooraPreTable">'. $gridPager .'</div>' : null ) .
                $gridTable . 
                (!$hasNoResults && (isset($arrGridData['table']['options']['bottomPager']) && $arrGridData['table']['options']['bottomPager'] !== false && $gridPager) ? '<div class="hathooraPostTable"> '. $gridPager .'</div>' : null) .
                $htmlAppend .'
            </div>';
        }
        // is ajx call
        else
        {
            if ($ajaxCalls)
            {
                $grid = '
                <script type="text/javascript">
                    var hathooraGrid = hathooraGrid || {"tables": {}};
                    $(document).ready(function()
                    {
                        // load hathooraGrid if not already loaded
                        if (jQuery().hathooraGrid == undefined)
                        {
                            $.ajax({
                                url: "'. $hathooraGridJS .'",
                                dataType: "script",
                                cache: true,
                                async: false,
                                success: function(){}
                            });
                        }

                        hathooraGrid["tables"]["'.$table_id.'"] = {
                                                        "id":  "'. $table_id .'",
                                                        "sort":  "'. $arrGridData['sort'] .'",
                                                        "order":  "'. $arrGridData['order'] .'",
                                                        "page": "'. $arrGridData['page'] .'",
                                                        "url": "' . $arrGridData['table']['sort']['url'] .'",
                                                        "limit": "'. $arrGridData['limit'] .'",
                                                        "dynamic": "'. (!empty($arrGridData['table']['fields']['dynamic']) ? 1 : 0 ).'",
                                                        "columns": '. json_encode($arrGridData['table']['columnsJS']) .' }

                        $("#'. $table_id .'").hathooraGrid({"onReady": '. $onGridReadyCallBack .'});
                    });
                </script>';
            }

            $grid .=
            ( !empty($arrGridData['table']['options']['topPager']) ? '<div class="hathooraPreTable">'. $gridPager .'</div>' : null ) .
            $gridTable .
            (!$hasNoResults && (isset($arrGridData['table']['options']['bottomPager']) && $arrGridData['table']['options']['bottomPager'] !== false && $gridPager) ? '<div class="hathooraPostTable"> '. $gridPager .'</div>' : null) .
            $htmlAppend;
        }

        return $grid;
    }
public static function renderGrid(&$arrGridData, $return = false)
    {
        $table_id = isset($arrGridData['table']['id']) ? $arrGridData['table']['id'] : 'htgrid_'. time() . rand(1,99999);
        $table_class = isset($arrGridData['table']['class']) ? $arrGridData['table']['class'] : null;
        $grid = $noResultsTableClass = $hasNoResults = null;

        $hathooraGridJS = '/_assets/_hathoora/hathooraGrid.js';
        if (!empty($arrGridData['javascript']['gridPluginURL']))
            $hathooraGridJS = $arrGridData['javascript']['gridPluginURL'];

        $gridHeader = $gridPager = $gridTable = $gridPager = null;
        $htmlAppend = isset($arrGridData['html']['append']) ? $arrGridData['html']['append'] : null;
        $table_id = $arrGridData['table']['id'];
        $onGridReadyCallBack = !empty($arrGridData['javascript']['onGridReadyCallBack']) ? $arrGridData['javascript']['onGridReadyCallBack'] : 'null';
        $ajaxCalls = isset($arrGridData['javascript']['ajax']) ? $arrGridData['javascript']['ajax'] : true;

        // pagination?
        if (empty($arrGridData['table']['pagination']))
            $arrGridData['table']['pagination'] = array('\hathoora\grid\pagination', 'simple');
        else if (is_string($arrGridData['table']['pagination']))
            $arrGridData['table']['pagination'] = array('\hathoora\grid\pagination', $arrGridData['table']['pagination']);
        
        if (isset($arrGridData['table']['template']))
            require($arrGridData['table']['template']);
        // load default template
        else
            require(__DIR__ .'/template.php');

        $gridPager = trim($gridPager);

        if (!empty($arrGridData['debug']))
            $htmlAppend .= '<br/><br/>' . $arrGridData['queryTotal'] . '<br/><br/>' . $arrGridData['queryRow'] . '<br/><pre>'. print_r($arrGridData, true) .'</pre>';

        // when not ajax call
        if (empty($arrGridData['pajax']))
        {
            $grid = $gridHeader .'
            <div id="'. $table_id .'_inner" htg-table_id="'. $table_id .'" class="hathooraGrid '. $table_class .' ' .$noResultsTableClass .'">';

            if ($ajaxCalls)
            {
                $grid .= '
                 <script type="text/javascript">
                    var hathooraGrid = hathooraGrid || {"tables": {}};
                    $(document).ready(function()
                    {
                        // load hathooraGrid if not already loaded
                        if (jQuery().hathooraGrid == undefined)
                        {
                            $.ajax({
                                url: "'. $hathooraGridJS .'",
                                dataType: "script",
                                async: false,
                                cache: true,
                                success: function(){}
                            });
                        }
                        
                        hathooraGrid["tables"]["'.$table_id.'"] = {
                                                                    "id":  "'. $table_id .'",
                                                                    "sort":  "'. $arrGridData['sort'] .'",
                                                                    "order":  "'. $arrGridData['order'] .'",
                                                                    "page": "'. $arrGridData['page'] .'",
                                                                    "url": "' . $arrGridData['table']['sort']['url'] .'",
                                                                    "limit": "'. $arrGridData['limit'] .'",
                                                                    "dynamic": "'. (!empty($arrGridData['table']['fields']['dynamic']) ? 1 : 0 ).'",
                                                                    "columns": '. (!empty($arrGridData['table']['columnsJS']) ? json_encode($arrGridData['table']['columnsJS']) : '{}') .'
                                                                }

                        $("#'. $table_id .'").hathooraGrid({"onReady": '. $onGridReadyCallBack .', "isHackReady": true});
                    });
                </script>';
            }

            $grid .=
                (!empty($arrGridData['table']['options']['topPager']) ? '<div class="hathooraPreTable">'. $gridPager .'</div>' : null ) .
                $gridTable . 
                (!$hasNoResults && (isset($arrGridData['table']['options']['bottomPager']) && $arrGridData['table']['options']['bottomPager'] !== false && $gridPager) ? '<div class="hathooraPostTable"> '. $gridPager .'</div>' : null) .
                $htmlAppend .'
            </div>';
        }
        // is ajx call
        else
        {
            if ($ajaxCalls)
            {
                $grid = '
                <script type="text/javascript">
                    var hathooraGrid = hathooraGrid || {"tables": {}};
                    $(document).ready(function()
                    {
                        // load hathooraGrid if not already loaded
                        if (jQuery().hathooraGrid == undefined)
                        {
                            $.ajax({
                                url: "'. $hathooraGridJS .'",
                                dataType: "script",
                                cache: true,
                                async: false,
                                success: function(){}
                            });
                        }

                        hathooraGrid["tables"]["'.$table_id.'"] = {
                                                        "id":  "'. $table_id .'",
                                                        "sort":  "'. $arrGridData['sort'] .'",
                                                        "order":  "'. $arrGridData['order'] .'",
                                                        "page": "'. $arrGridData['page'] .'",
                                                        "url": "' . $arrGridData['table']['sort']['url'] .'",
                                                        "limit": "'. $arrGridData['limit'] .'",
                                                        "dynamic": "'. (!empty($arrGridData['table']['fields']['dynamic']) ? 1 : 0 ).'",
                                                        "columns": '. json_encode($arrGridData['table']['columnsJS']) .' }

                        $("#'. $table_id .'").hathooraGrid({"onReady": '. $onGridReadyCallBack .'});
                    });
                </script>';
            }

            $grid .=
            ( !empty($arrGridData['table']['options']['topPager']) ? '<div class="hathooraPreTable">'. $gridPager .'</div>' : null ) .
            $gridTable .
            (!$hasNoResults && (isset($arrGridData['table']['options']['bottomPager']) && $arrGridData['table']['options']['bottomPager'] !== false && $gridPager) ? '<div class="hathooraPostTable"> '. $gridPager .'</div>' : null) .
            $htmlAppend;
        }

        return $grid;
    }
Render grid given an array of data\table

@param array $arrGridData
@param bool $return or echo
@return string