        
<div class="right">
<table id="header-fixed"></table>
    <table class="table table-striped table-hover table-bordered table-condensed" id="gridView">
        <thead>
            <tr class="nodrag">
                <?php foreach((array)$grid_data as $key=>$item): ?>
                    <?php if($item['show'] && $table_fields[$key]): ?>                  
                        <th field="<?php echo $key; ?>"><?php if($table_fields[$key]['title']) echo $table_fields[$key]['title']; else echo _t($key) ?>
                            <?php if($_SESSION['sorting'][$table]['field']==$key): ?>
                                <i class="header-sort fa fa-sort-<?php if($_SESSION['sorting'][$table]['direction']=='ascending') echo 'up'; else echo 'down'; ?>">
                            <?php endif ?>
                        </th>
                    <?php endif ?>
                <?php endforeach ?>
                <th style="cursor: default;">&nbsp;</th>
            </tr>
        </thead>
        <tbody>

            <?php foreach((array)$data as $key=>$item): $color=''; ?>                
                <?php foreach((array)$table_info['tabConditionColor'] as $kc=>$cc) {

                    if($item[$cc['tab#cc_field']] || $item[$cc['tab#cc_field'].'@'.$cfg['admin']['language']]) {
                        $ftest=$cc['tab#cc_field'];
                        if(!$ftest) $ftest=$cc['tab#cc_field'].'@'.$cfg['admin']['language'];    
                                        
                        switch($cc['tab#cc_operator']) {
                            case 'like':
                              //echo $item[$ftest];
                                if(strpos($item[$ftest], $cc['tab#cc_value'])!==false) $color=$cc['tab#cc_color'];
                            break;
                        }
                    }  
                    
                } ?>                
                <tr<?php if($color) echo ' class="cc"';?> rid="<?php echo $item[$table_config['idField']]; ?>">  
                    <?php foreach((array)$grid_data as $k=>$i): ?>  
                        <?php if($i['show']): ?>
                            <?php if($table_fields[$k]['language']) $fkey=$k.'@'.$cfg['admin']['language']; else $fkey=$k; ?>                            
                            <td<?php if($color) echo ' style="background-color: '.$color.'"'; ?> ftype="<?php echo $table_fields[$k]['type']; ?>" field="<?php if($table_fields[$k]['language']) echo $k.'@'.$cfg['admin']['language']; else echo $k; ?>"><?php
                                $field=$table_fields[$k];  
                                //echo $table_fields[$k]['type'];                           
                                switch($table_fields[$k]['type']) {
                                    case 'id':
                                        echo '<span style="color: #606060; font-weight: bold;">#</span>'.$item[$fkey]; 
                                    break;
                                    case 'text': 
                                        echo $item[$fkey];
                                    break;
                                    case 'select':                                                           
                                        echo $field['labels'][array_search($item[$fkey], $field['values'])];
                                    break;
                                    case 'link_button':
                                        echo '<a target="_blank" class="btn btn-info btn-xs" href="'.str_replace('{id}', $item[$table_config['idField']], $field['link']).'">'.$field['title'].'</a>';                                    
                                    break; 
                                    case 'htmlarea':
                                        echo '<div style="max-width: 150px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap;">'.substr(strip_tags($item[$fkey]),0,200).'</div>';
                                    break;
                                    case 'rel_one2many':
                                        if(!$item[$field['relationfield']]) $item[$field['relationfield']]=$item[$field['relationfield'].'@'.$_SESSION['edit_language']];
                                        if($item[$field['relationfield']]) {
                                            echo '<i class="fa fa-external-link-square relation-ident"></i> '.$item[$field['relationfield']];
                                        } 
                                        //print_r($field);               
                                    break;                                                                       
                                    default:
                                        echo '<span style="color: #707070;">'.$item[$fkey].'</span>';                                        
                                    break;
                                }
                                ?></td>
                        <?php endif ?>
                    <?php endforeach ?>
                    
                        <td<?php if($color) echo ' style="background-color: '.$color.'"'; ?>><div class="btn-group btn-group-xs" style="float: right;">
                            <?php foreach((array)$xtra_buttons as $k=>$button): ?>                        
                                <?php $url=str_replace(array('{id}'), array($item[$table_config['idField']]), $button['url']);
                                    if($table=='tables') { $tabl=$row['tabName']; } else { $tabl=$table; } ?>
                                    <a class="btn btn-<?php echo $button['class']?>" type="button" href="<?php echo $url ?>"<?php echo perm_display($tabl,$button['perm'])?>><span class="glyphicon <?php echo $button['icon']?>"></span> <?php echo $button['label'] ?></a>
                            <?php endforeach ?>
                            
                            <button class="btn btn-primary rel_select" type="button"<?php if(!$_GET['modal_view']) echo ' style="display: none;"';?>><span class="glyphicon glyphicon-hand-up"></span> wybierz</button>
                                          
                            <a class="btn btn-default" type="button" href="/<?php echo $_url[0]?>/<?php echo $_url[1]?>/edit?id=<?php echo $item[$table_config['idField']].$table_config['linkEdit']?>"<?php echo perm_display($table,'edit')?>><span class="glyphicon glyphicon-edit"></span> edytuj</a>
                            <button class="btn btn-default" type="button" style="display: none;"><span class="glyphicon glyphicon-asterisk"></span> duplikuj</button>
                            <a class="btn btn-danger ajaxModal" type="button" href="/<?php echo $_url[0].'/ajax/remove_record?table='.$table.'&id='.$item[$table_config['idField']]?>"<?php echo perm_display($table,'remove')?>><span class="glyphicon glyphicon-fire"></span> usuń</a>          
                        </div></td>                    
                    
                </tr>
            <?php endforeach ?>
        </tbody>
    </table>

</div>
    
    
<div class="panel-footer">
    <ul class="pagination">
        <li><a>«</a></li><li id="pagReplace"><a>...</a></li><li><a>»</a></li>
    </ul>
    <div class="label label-default" style="display: block; float: left; margin-top: 10px;">Rekordy <span id="recFrom">...</span> - <span id="recTo">...</span> z <?php echo $_total ?></div>
    <div class="clear"></div>
</div>
   
<input type="hidden" name="grid_page" value="<?php echo $page+1;?>"/>
<input type="hidden" name="grid_total" value="<?php echo $_total ?>"/>
<input type="hidden" name="url_request" value="<?php echo $_SERVER['REQUEST_URI'] ?>"/> 

<script type="text/javascript">

    var hexDigits = new Array
            ("0","1","2","3","4","5","6","7","8","9","a","b","c","d","e","f"); 
    
    //Function to convert hex format to a rgb color
    function rgb2hex(rgb) {
     rgb = rgb.match(/^rgb\((\d+),\s*(\d+),\s*(\d+)\)$/);
     return "#" + hex(rgb[1]) + hex(rgb[2]) + hex(rgb[3]);
    }
    
    function hex(x) {
      return isNaN(x) ? "00" : hexDigits[(x - x % 16) / 16] + hexDigits[x % 16];
     }

    $('.remove-filter-item').click(function() {
        $('#form_search input[name=action]').val('remove_search');
        $('#form_search input[name=phrase]').val($(this).attr('phrase'));
        $('#fullOverlay').css('display', 'block');
        $('#form_search').submit();
    });    
    
    <?php if($_POST['action']=='add_search' || $_POST['action']=='remove_search'): ?>
        //$('#search_input').focus();
    <?php endif ?>
    
    
    // wyroznij co drugi rekord
    var index=1; 
    $('table#gridView tbody tr').each(function() {
        //alert('xx');
        if(index % 2==0) {
          ///alert('aa');
            if($(this).hasClass('cc')) {
                rgb = $(this).find('td').css('background-color').match(/^rgb\((\d+),\s*(\d+),\s*(\d+)\)$/);
                $(this).find('td').css('background-color', 'rgba('+rgb[1]+','+rgb[2]+','+rgb[3]+',0.7)');
                //$(this).find('td').css('background-color', '#ce0000');    
            }
            
        }
        index++;
    });  
    
    
    
    // edycja inline'owa
    $('td[ftype=text]').dblclick(function() {
        $('input[inline-value]').each(function() {
            $(this).after($(this).attr('inline-value')).remove();
        });
        $(this).addClass('inline-edit');
        $(this).html('<input class="form-control input-sm" type="text" inline-value="'+$(this).html()+'" value="'+$(this).html()+'"/>');
        $('input[inline-value]').focus().val($('input[inline-value]').val());
    });
    
    $('body').on('blur', 'input[inline-value]', function() {
        $('#fullOverlay').css('display', 'block');
        $('input[inline-value]').addClass('saving');
        //alert($('input[inline-value]').parent().parent().attr('rid'));
        $.post(url_ajax+'/inline_set', {'table':_table, 'id':$('input[inline-value]').parent().parent().attr('rid'), 'field':$('input[inline-value]').parent().attr('field'), 'value':$('input[inline-value]').val()}, function(data) {
            
            if(data=='OK') {
                $('input[inline-value]').after($('input[inline-value]').val()).remove();  
            } else {
                $('input[inline-value]').after($('input[inline-value]').attr('inline-value')).remove();
            }                                  
            $('#fullOverlay').css('display', 'none');              
        });
         
                
    });
    
    $('body').on('keyup', 'input[inline-value]', function(e) {
        //alert(e.which+ ' / '+e.keyCode);
        if(e.which==27) {
            $('input[inline-value]').after($('input[inline-value]').attr('inline-value')).remove();   
        }
        if(e.which==13) {
            $('input[inline-value]').trigger('blur');
        }
    });
    
    $('.rel_select').click(function() {
        $('#fullOverlay').css('display', 'block');
        var ob=window.parent.$('body').find('.relationCurrentField');
        ob.val($(this).parents('tr').attr('rid'));
        //alert(   window.parent.$('body').find('.relationCurrentField').prev().val()  );
        $.get(url_ajax+"/get_relation_value?id="+$(this).parents('tr').attr('rid')+"&table="+_table+"&field="+window.btoa(encodeURIComponent(window.parent.$('body').find('.relationCurrentField').prev().val())), function(data) {
            ob.next('.form-control').val(data);
            window.parent.$('body').find('#fullOverlay').css('display', 'none');               
            window.parent.$('iframe.fullscreen').first().remove();   
              
        });
        //alert($(this).parents('tr').attr('rid'));    
    });
    
    if ( self !== top ) {
        $('.rel_select').css('display', 'block');    
    }
    
    $('th[field]').click(function() {
        $('#form_sorting input[name=field]').val($(this).attr('field'));
        if($(this).find('i.fa-sort-up').length>0) {
            $('#form_sorting input[name=direction]').val('descending');
        } else {
            $('#form_sorting input[name=direction]').val('ascending');
        } 
        $('#fullOverlay').css('display', 'block');
        $('#form_sorting').submit();
        
    });
    
    


</script>