2013-07-16 74 views
0

我有一個這樣的網格:如何在jqgrid中隱藏行?

//Barang 
//label_name 
var label_name = ["No", "Part Number", "Part Name", "Price", "Pallete", "UOM", "QTY", "Total", "Action"]; 


var getLabel = $("#label_name").val(); 
var arr_label = getLabel.split(','); 
var n = arr_label; 
for(i=0;i<n.length;i++){ 
    //label_name.push(n[i]); 
} 
//label_name.push("Total Demand", "Avarage Demand", "Nilai Total Pengguna Uang", "HIT", "Nilai Persediaan(Value*HIT)"); 


//content_name 
var content_name = [ 
    {name:'no', index:'no', width:50, align:"right", editable:false, editoptions:{readonly:true}, sorttype:'int', searchoptions:{sopt:['eq']}, search:false}, 
    {name:'part_number', index:'part_number', width:200, sortable:false, editable:true, searchoptions:{sopt:['eq']}}, 
    {name:'part_name', index:'part_name', width:200, editable:true, searchoptions:{sopt:['eq']}}, 
    {name:'price', index:'price', width:150, align:"right", editable:true, editrules:{number:true}, sorttype:'number', formatter:'number', searchoptions:{sopt:['eq']}}, 
    {name:'pallete', index:'pallete', width:100, sortable:false, editable:true, searchoptions:{sopt:['eq']}, search:false}, 
    {name:'uom', index:'uom', width:100, editable:true, searchoptions:{sopt:['eq']}, search:false}, 
    {name:'qty', index:'qty', width:100, editable:true, searchoptions:{sopt:['eq']}, search:false}, 
    {name:'total', index:'total', width:100, editable:true, searchoptions:{sopt:['eq']}, search:false}, 
    {name:'action', index:'action', width:100, editable:true, searchoptions:{sopt:['eq']}, search:false} 
]; 


var getLabel = $("#label_name").val(); 
var arr_label = getLabel.split(','); 
var n = arr_label; 
for(i=0;i<n.length;i++){ 
    //content_name.push({name:n[i], index:n[i], width:45, align:"right", sortable:false, editable:false}); 
} 
/* 
content_name.push(
    {name:'total_demand', index:'total_demand', width:50, align:"right", sortable:false, editable:false}, 
    {name:'average_demand', index:'average_demand', width:50, align:"right", sortable:false, editable:false}, 
    {name:'ntpu', index:'ntpu', width:80, align:"right", sortable:false, editable:false, formatter:'number'}, 
    {name:'hit', index:'hit', width:30, align:"right", sortable:false, editable:false}, 
    {name:'nilai_persediaan', index:'nilai_persediaan', width:80, align:"right", sortable:false, editable:false, formatter:'number'} 
); 
*/ 

jQuery("#barang").jqGrid({ 
    url:'load_barang.php', 
    datatype: "json", 
    colNames:label_name, 
    colModel:content_name, 
    rowNum:10, 
    rowTotal: 50, 
    rowList:[10,20,30], 
    pager: '#pbarang', 
    sortname: 'id', 
    loadonce: true, 
    viewrecords: true, 
    sortorder: "desc", 
    editurl: 'server.php', // this is dummy existing url 
    caption:"Modul Barang", 
    shrinkToFit: false, 
    height: 'auto' 
}); 
//jQuery("#barang").jqGrid('navGrid','#pbarang',{}); 
jQuery("#barang").jqGrid('navGrid','#pbarang',{edit:false,add:false,del:false}); 
jQuery("#barang").jqGrid('gridResize',{minWidth:350,maxWidth:true,minHeight:80, maxHeight:true}); 
jQuery("#barang").jqGrid('hideCol',["total"]); 

//Resizable Grid 
$("#barang").resizable({ 
    grid: 50 
}); 

//Merge 
jQuery("#barang").jqGrid('setGroupHeaders', { 
    useColSpanStyle: true, 
    groupHeaders:[ 
    {startColumnName: n[0], numberOfColumns: n.length, titleText: '<center>Demand</center>'} 
    //{startColumnName: 'closed', numberOfColumns: 2, titleText: 'Shiping'} 
    ] 
}); 

//Hide and Show 
jQuery("#hcg").click(function() { 
    jQuery("#barang").jqGrid('hideCol',["total"]); 
}); 
jQuery("#scg").click(function() { 
    jQuery("#barang").jqGrid('showCol',["total"]); 
}); 

我已經嘗試過按照這樣的回答驗證碼$("#"+rowid).hide() - >jqgrid hide row inside grid

但它並不在我的工作網格

請幫助我。 謝謝。

+0

鏈接的答案似乎像它應該工作 - 會發生什麼,當你嘗試在你的網格?另外,你確定你確實想隱藏行嗎?可能有其他更直接的解決方案,例如根據需要檢索數據,以某種方式應用過濾器,刪除行(但將數據保存到JavaScript對象)等等。 –

+0

行未隱藏,這就是發生了。請幫忙。順便說一句,如果我使用$(「#」+ rowid).hide()'它應該是$(「#barang」4).hide(); - >根據我的網格,對不對? –

+0

嘗試$('#4','#barang')。hide(); –

回答

0

試試這個:

$("#row_id","#barang").css({display:"none"}) 
+0

這應該可行,雖然'hide'比'css'更適合... –