jQuery 选项卡中的多个 slickGrid

发布于 2024-10-13 09:44:20 字数 839 浏览 2 评论 0原文

我正在创建多个 slickGrid 并将它们放入 jQuery 选项卡中。 第一个 jQuery 选项卡上的第一个 slickGrid 工作正常,但是当我切换到下一个选项卡时 在调整标题大小并且列未与标题对齐之前,slickGrid 上的数据列不会显示。有什么办法可以解决这个问题吗? 这是我的代码摘录:

<ul class="tabs">
     <li><a href="#tab_1">FADF Mono</a></li>
     <li><a href="#tab_2">BADF Mono</a></li>
     <li><a href="#tab_3">BADF Color</a></li>
</ul>
<div class="tab_container">
       <div id="tab_1" class="tab_content">
          <div id="slickGrid_1"></div>
       </div>
       <div id="tab_2" class="tab_content">
          <div id="slickGrid_2"></div>
       </div>
       <div id="tab_3" class="tab_content">
          <div id="slickGrid_3"></div>
       </div>
</div>

I am creating multiple slickGrids and puts them in a jQuery tab.
The first slickGrid on the first jQuery tab works fine, but when I switch to the next tab
the data columns on the slickGrid does not show up until you resize the header and the columns are not aligned to the header. Is there any way I can fix this?
here's my code exerp:

<ul class="tabs">
     <li><a href="#tab_1">FADF Mono</a></li>
     <li><a href="#tab_2">BADF Mono</a></li>
     <li><a href="#tab_3">BADF Color</a></li>
</ul>
<div class="tab_container">
       <div id="tab_1" class="tab_content">
          <div id="slickGrid_1"></div>
       </div>
       <div id="tab_2" class="tab_content">
          <div id="slickGrid_2"></div>
       </div>
       <div id="tab_3" class="tab_content">
          <div id="slickGrid_3"></div>
       </div>
</div>

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(4

一桥轻雨一伞开 2024-10-20 09:44:20

好的。好吧,我会尝试分解正在发生的事情以及为什么它不起作用。基本上可能发生的情况是,您在初始化 slickgrid 实例之前设置选项卡。了解这一点很重要,因为您的第二个和第三个选项卡本质上被赋予隐藏状态,因此您的光滑网格不会初始化。

尝试更改顺序,看看是否有效。如果没有,那么我建议将 slickfgrid 初始值设定项放入 document.ready 中,将选项卡初始值设定项放入 document.load 中。这有点hacky,但产生了很好的结果。

希望这是有道理的。

Okay. Well, I will try and break down what is going on and why it's nor working. Basically what is likely happening is that you are setting your tabs before you initialise your slickgrid isntances. This is important to know, because your second and third tabs are essentially given a hidden state and therefor your slickgrids are not initialising.

Try changing the order and see if that works. If it doesn't then I recommend putting your slickfgrid initializers into document.ready and your tab initializer into document.load. It's a little hacky, but yields good results.

Hope this makes sense.

深陷 2024-10-20 09:44:20

您应该将网格加载移动到 jQuery 选项卡的“show”事件中。我必须使用这些事件而不是 document.ready/load ,因为我没有显示选项卡的 CSS 来删除“选项卡闪烁”,即使这种情况发生在页面加载和选项卡初始化时。我有这样的东西:

    $('#tabs').tabs({
            fx: [
                    {opacity: 'toggle', duration: 'fast'},
                    {opacity: 'toggle', duration: 'fast'}
            ],
            show: function(event, ui) {
                    if($(ui.tab).text() == "grids" && !this.gloaded) {
                            grids.init();
                            this.gloaded = true;
                    }
            }
    });

You should move the grid loading into the "show" event of the jQuery tab. I had to use these events instead of document.ready/load because I have my tabs' CSS displayed none to remove the "tab flash" even that happens right as the page loads and the tabs are being initialized. Something like this is what I have:

    $('#tabs').tabs({
            fx: [
                    {opacity: 'toggle', duration: 'fast'},
                    {opacity: 'toggle', duration: 'fast'}
            ],
            show: function(event, ui) {
                    if($(ui.tab).text() == "grids" && !this.gloaded) {
                            grids.init();
                            this.gloaded = true;
                    }
            }
    });
腹黑女流氓 2024-10-20 09:44:20

看来您可能正在努力解决我遇到的同样问题。 Jquery 选项卡隐藏行为会遇到 IE 和 Chrome 上的 slickgrid 渲染问题。 FIrefox 渲染得很好。
这就是我要说的——
对 jquery UI CSS 进行以下修改 -

.ui-tabs .ui-tabs-hide { display: none !important; }

.ui-tabs .ui-tabs-hide {
    position: absolute;
    left: -10000px;
}

Seems like you possibly are struggling with the same issue i was running into. Jquery tabs hiding behavior runs into slickgrid rendering on IE and chrome. FIrefox renders it fine.
This is what I'm talking about -
Make the following modification to jquery UI CSS -

from

.ui-tabs .ui-tabs-hide { display: none !important; }

to

.ui-tabs .ui-tabs-hide {
    position: absolute;
    left: -10000px;
}
与往事干杯 2024-10-20 09:44:20

这基本上是我的 jquery 的代码重构,该代码是由 php 代码动态生成的。

    $(document).ready(function() {

    //When page loads...
    $(".tab_content").hide(); //Hide all content
    $("ul.tabs li:first").addClass("active").show(); //Activate first tab
    $(".tab_content:first").show(); //Show first tab content

    //On Click Event
    $("ul.tabs li").click(function() {

        $("ul.tabs li").removeClass("active"); //Remove any "active" class
        $(this).addClass("active"); //Add "active" class to selected tab
        $(".tab_content").hide(); //Hide all tab content

        var activeTab = $(this).find("a").attr("href"); //Find the href attribute value to identify the active tab + content
        $(activeTab).fadeIn(); //Fade in the active ID content
        return false;
    });

    });
    </script>
    <script>
var grid_1;     
var columns_1 = [           
{id:"title", name:"Title", field:"title"},          
{id:"duration", name:"Duration", field:"duration"},         
{id:"%", name:"% Complete", field:"percentComplete"},           
{id:"start", name:"Start", field:"start"},          
{id:"finish", name:"Finish", field:"finish"},           
{id:"effort-driven", name:"Effort Driven", field:"effortDriven"}        
];

var options_1 = {           
enableCellNavigation: false,          
enableColumnReorder: false      
};

$(function() {         
var data_1 = [];            
for (var i = 0; i < 500; i++) {             
data[i] = {                 
title: "Task " + i,                  
duration: "5 days",                  
percentComplete: Math.round(Math.random() * 100),                 
 start: "01/01/2009",                  
 finish: "01/05/2009",                   
effortDriven: (i % 5 == 0)             
 };         
}

grid_1 = new Slick.Grid($("#slickGrid_1"), data_1, columns_1, options_1);       
})      
</script>

<script>        
var grid_2;     
var columns_2 = [           
{id:"title", name:"Title", field:"title"},          
{id:"duration", name:"Duration", field:"duration"},         
{id:"%", name:"% Complete", field:"percentComplete"},           
{id:"start", name:"Start", field:"start"},          
{id:"finish", name:"Finish", field:"finish"},           
{id:"effort-driven", name:"Effort Driven", field:"effortDriven"}        
];      
var options_2 = {           
enableCellNavigation: false,           
enableColumnReorder: false      
};

$(function() {          
var data_2 = [];            
for (var i = 0; i < 500; i++) {             
data[i] = {                   
title: "Task " + i,                   
duration: "5 days",                  
percentComplete: Math.round(Math.random() * 100),                   
start: "01/01/2009",                  
finish: "01/05/2009",                   
effortDriven: (i % 5 == 0)              
 };         
}           
grid_2 = new Slick.Grid($("#slickGrid_2"), data_2, columns_2, options_2);       
})      
</script>

<script>        
var grid_3;     
var columns_3 = [       
{id:"title", name:"Title", field:"title"},          
{id:"duration", name:"Duration", field:"duration"},         
{id:"%", name:"% Complete", field:"percentComplete"},           
{id:"start", name:"Start", field:"start"},          
{id:"finish", name:"Finish", field:"finish"},           
{id:"effort-driven", name:"Effort Driven", field:"effortDriven"}        
];

var options_3 = {           
enableCellNavigation: false,          
enableColumnReorder: false      
};

$(function() {         
var data_3 = [];            
for (var i = 0; i < 500; i++) {             
data[i] = {                   
title: "Task " + i,                   
duration: "5 days",                   
percentComplete: Math.round(Math.random() * 100),                  
start: "01/01/2009",                  
finish: "01/05/2009",                   
effortDriven: (i % 5 == 0)               
 };         
}
grid_3 = new Slick.Grid($("#slickGrid_3"), data_3, columns_3, options_3);
})
</script>

this basically is a code reconstruction of my jquery, this code is dynamically generated by a php code.

    $(document).ready(function() {

    //When page loads...
    $(".tab_content").hide(); //Hide all content
    $("ul.tabs li:first").addClass("active").show(); //Activate first tab
    $(".tab_content:first").show(); //Show first tab content

    //On Click Event
    $("ul.tabs li").click(function() {

        $("ul.tabs li").removeClass("active"); //Remove any "active" class
        $(this).addClass("active"); //Add "active" class to selected tab
        $(".tab_content").hide(); //Hide all tab content

        var activeTab = $(this).find("a").attr("href"); //Find the href attribute value to identify the active tab + content
        $(activeTab).fadeIn(); //Fade in the active ID content
        return false;
    });

    });
    </script>
    <script>
var grid_1;     
var columns_1 = [           
{id:"title", name:"Title", field:"title"},          
{id:"duration", name:"Duration", field:"duration"},         
{id:"%", name:"% Complete", field:"percentComplete"},           
{id:"start", name:"Start", field:"start"},          
{id:"finish", name:"Finish", field:"finish"},           
{id:"effort-driven", name:"Effort Driven", field:"effortDriven"}        
];

var options_1 = {           
enableCellNavigation: false,          
enableColumnReorder: false      
};

$(function() {         
var data_1 = [];            
for (var i = 0; i < 500; i++) {             
data[i] = {                 
title: "Task " + i,                  
duration: "5 days",                  
percentComplete: Math.round(Math.random() * 100),                 
 start: "01/01/2009",                  
 finish: "01/05/2009",                   
effortDriven: (i % 5 == 0)             
 };         
}

grid_1 = new Slick.Grid($("#slickGrid_1"), data_1, columns_1, options_1);       
})      
</script>

<script>        
var grid_2;     
var columns_2 = [           
{id:"title", name:"Title", field:"title"},          
{id:"duration", name:"Duration", field:"duration"},         
{id:"%", name:"% Complete", field:"percentComplete"},           
{id:"start", name:"Start", field:"start"},          
{id:"finish", name:"Finish", field:"finish"},           
{id:"effort-driven", name:"Effort Driven", field:"effortDriven"}        
];      
var options_2 = {           
enableCellNavigation: false,           
enableColumnReorder: false      
};

$(function() {          
var data_2 = [];            
for (var i = 0; i < 500; i++) {             
data[i] = {                   
title: "Task " + i,                   
duration: "5 days",                  
percentComplete: Math.round(Math.random() * 100),                   
start: "01/01/2009",                  
finish: "01/05/2009",                   
effortDriven: (i % 5 == 0)              
 };         
}           
grid_2 = new Slick.Grid($("#slickGrid_2"), data_2, columns_2, options_2);       
})      
</script>

<script>        
var grid_3;     
var columns_3 = [       
{id:"title", name:"Title", field:"title"},          
{id:"duration", name:"Duration", field:"duration"},         
{id:"%", name:"% Complete", field:"percentComplete"},           
{id:"start", name:"Start", field:"start"},          
{id:"finish", name:"Finish", field:"finish"},           
{id:"effort-driven", name:"Effort Driven", field:"effortDriven"}        
];

var options_3 = {           
enableCellNavigation: false,          
enableColumnReorder: false      
};

$(function() {         
var data_3 = [];            
for (var i = 0; i < 500; i++) {             
data[i] = {                   
title: "Task " + i,                   
duration: "5 days",                   
percentComplete: Math.round(Math.random() * 100),                  
start: "01/01/2009",                  
finish: "01/05/2009",                   
effortDriven: (i % 5 == 0)               
 };         
}
grid_3 = new Slick.Grid($("#slickGrid_3"), data_3, columns_3, options_3);
})
</script>
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文