2012-05-10 29 views
17

Một số người có thể giúp tôi, tôi có một jqgrid và tôi muốn đánh dấu hàng nếu hộp kiểm là đúng, cảm ơn !!Đánh dấu hàng khi hộp kiểm là đúng

enter image description here

đây là những gì tôi muốn làm trong dự án này ...

function loadjqGrid(jsonGridData){ 
    var xaxis=1300 
    var yaxis = $(document).height(); 
    yaxis = yaxis-500; 
    getGrids();  
    $("#maingrid").jqGrid({ 
     url:'models/mod.quoservicetypedetails.php?ACTION=view', 
     mtype: 'POST', 
     datatype: 'xml', 
     colNames:getColumnNames(jsonGridData), 
     colModel :[ 
      {name:'TypeID', index:'TypeID', width:350,hidden:true, align:'center',sortable:false,editable:true, 
      edittype:"select",editoptions:{value:getTypeID()},editrules: { edithidden: true}}, 
      {name:'Order1', index:'Order1', width:80, align:'center',sortable:false,editable:true,edittype:"textarea",editoptions:{size:"30",maxlength:"30"}},     
      {name:'Order2', index:'Order2', width:80, align:'center',sortable:false,editable:true,edittype:"textarea",editoptions:{size:"30",maxlength:"30"}}, 
      {name:'Order3', index:'Order3', width:80, align:'center',sortable:false,editable:true,edittype:"textarea",editoptions:{size:"30",maxlength:"30"}},      
      {name:'Description', index:'Description', width:140, align:'center',sortable:false,editable:true, 
      edittype:"textarea",editoptions:{size:"30",maxlength:"30"}},      
      {name:'Notes', index:'Notes', width:120, align:'center',sortable:false,editable:true,edittype:"textarea",editoptions:{size:"30",maxlength:"30"}}, 
      {name:'Measure', index:'Measure', width:80, align:'center',sortable:false,editable:true, edittype:"textarea", editoptions:{size:"30",maxlength:"30"}},     
      {name:'UnitPrice', index:'UnitPrice', width:100, align:'center',sortable:false,editable:false,edittype:"textarea",editoptions:{size:"30",maxlength:"30"}}, 
      {name:'Remarks', index:'Remarks', width:140, align:'center',sortable:false,editable:true,edittype:"textarea",editoptions:{size:"30",maxlength:"30"}}, 
      {name:'UnitCost', index:'UnitCost', width:100, align:'center',sortable:false,editable:true,edittype:"textarea",editoptions:{size:"30",maxlength:"30"}},  
      {name:'Service', index:'Service', width:120, align:'center',sortable:false,editable:true,edittype:"textarea",editoptions:{size:"30",maxlength:"30"}}, 
      //If the GroupHeader is true the row background is yellow 
      {name:'GroupHeader', index:'GroupHeader', width:100, align:'center',sortable:false,editable:true,formatter:'checkbox', edittype:'checkbox', type:'select', editoptions:{value:"1:0"}}, 
      {name:'IsGroup', index:'IsGroup', width:80, align:'center',sortable:false,editable:true,formatter:'checkbox', edittype:'checkbox', type:'select', editoptions:{value:"1:0"}}, 
     ], 
     viewrecords: true, 
     rowNum:20, 
     sortname: 'id', 
     viewrecords: true, 
     sortorder: "desc", 
     height: yaxis, 
     pager : '#gridpager', 
     recordtext: "View {0} - {1} of {2}", 
     emptyrecords: "No records to view", 
     loadtext: "Loading...", 
     pgtext : "Page {0} of {1}",   
     height: yaxis, 
     width: xaxis, 
     shrinkToFit: false, 
     multiselect: true, 
     editurl:'models/mod.quoservicetypedetails.php?ACTION=edit' 
    }); 
} 

Làm thế nào tôi có thể làm điều này? Ai đó có thể giúp tôi?

+0

http://stackoverflow.com/ câu hỏi/6466750/how-to-select-jqgrid-row-on-checkbox-click –

+0

[link] https://lh5.googleusercontent.com/-Gda0KxFtUiM/T6uDOgi_YjI/AAAAAAAAAGw/Cdn74czGJ7A/w1519-h449-k/sample. JPG –

Trả lời

42

Tôi đã mô tả trong the answer một cách tốt để bạn có thể triển khai làm nổi bật.

Phiên bản 4.3.2 của jqGrid có tính năng mới - rowattr gọi lại (xem my original suggestion), được giới thiệu đặc biệt cho các trường hợp như của bạn. Nó cho phép bạn làm nổi bật một số hàng lưới trong khi điền của lưới. Để có lợi thế hiệu suất tốt nhất, bạn nên sử dụng thêm gridview: true. Nhân tiện Tôi khuyên bạn nên sử dụng gridview: true trong tất cả các jqGrids.

Việc sử dụng rowattr callback là rất dễ dàng:

gridview: true, 
rowattr: function (rd) { 
    if (rd.GroupHeader === "1") { // verify that the testing is correct in your case 
     return {"class": "myAltRowClass"}; 
    } 
} 

CSS lớp myAltRowClass cần xác định màu nền của hàng nhấn mạnh.

Bản demo tương ứng bạn có thể tìm here:

enter image description here

Bởi vì trong bản demo của bạn, bạn chỉ cần làm nổi bật và không chọn các hàng tôi đã không được sử dụng multiselect: true trong bản demo của tôi. Trong trường hợp của multiselect: true nó hoạt động chính xác theo cùng một cách.

Khi kết thúc câu trả lời của tôi, tôi muốn giới thiệu bạn sử dụng column templates. Tính năng này sẽ làm cho mã của bạn ngắn hơn, dễ đọc hơn và dễ bảo trì hơn. Những gì bạn cần làm là:

  • bạn có thể bao gồm cài đặt phổ biến hoặc thường được sử dụng nhất từ ​​định nghĩa cột trong cmTemplete. Trong trường hợp của bạn nó có thể là
cmTemplate: {align: 'center', sortable: false, editable: true, width: 80} 
  • sau đó bạn có thể định nghĩa một số biến trong đó mô tả tài sản chung mà bạn sử dụng thường xuyên trong một số cột. Ví dụ:
var myCheckboxTemplate = {formatter: 'checkbox', edittype: 'checkbox', type: 'select', 
     editoptions: {value: "1:0"}}, 
    myTextareaTemplate = {edittype: "textarea", 
     editoptions: {size: "30", maxlength: "30"}}; 
  • sau đó bạn có thể sử dụng myCheckboxTemplatemyTextareaTemplate bên trong colModel mà sẽ giảm trong trường hợp của bạn như sau
colModel: [ 
    {name: 'TypeID', index: 'TypeID', width: 350, hidden: true, edittype: "select", 
     editoptions: {value: getTypeID()}, editrules: { edithidden: true}}, 
    {name: 'Order1', index: 'Order1', template: myTextareaTemplate}, 
    {name: 'Order2', index: 'Order2', template: myTextareaTemplate}, 
    {name: 'Order3', index: 'Order3', template: myTextareaTemplate}, 
    {name: 'Description', index: 'Description', width: 140, template: myTextareaTemplate}, 
    {name: 'Notes', index: 'Notes', width: 120, template: myTextareaTemplate}, 
    {name: 'Measure', index: 'Measure', template: myTextareaTemplate}, 
    {name: 'UnitPrice', index: 'UnitPrice', width: 100, editable: false, template: myTextareaTemplate}, 
    {name: 'Remarks', index: 'Remarks', width: 140, template: myTextareaTemplate}, 
    {name: 'UnitCost', index: 'UnitCost', width: 100, template: myTextareaTemplate}, 
    {name: 'Service', index: 'Service', width: 120, template: myTextareaTemplate}, 
    //If the GroupHeader is true the row background is yellow 
    {name: 'GroupHeader', index: 'GroupHeader', width: 100, template: myCheckboxTemplate}, 
    {name: 'IsGroup', index: 'IsGroup', template: myCheckboxTemplate} 
], 
cmTemplate: {align: 'center', sortable: false, editable: true, width: 80}, 
+0

Nó hoạt động!Cảm ơn bạn rất nhiều, nhiều quyền lực hơn cho bạn @Oleg. –

+4

@JacxToi: Bạn được chào đón! Nếu vấn đề được giải quyết, bạn có thể ["chấp nhận"] (http://meta.stackexchange.com/a/5235/147495) câu trả lời. – Oleg

+0

Tuyệt vời! Cảm ơn sự giúp đỡ của bạn một lần nữa Oleg! Tôi có một "câu hỏi phụ" mà tôi nghĩ là có liên quan đến câu hỏi này. Bạn có thể vui lòng [** kiểm tra nó ở đây **] (http://stackoverflow.com/questions/19841588/jqgrid-change-background-color-of-grouping-header)? – FastTrack

Các vấn đề liên quan