2011-08-21 9 views
0

여러 개의 선택 상자와 텍스트 필드가있는 jqGrid가 있습니다. 모든 양식 필드를 같은 길이로하고 싶습니다. 모든 양식 필드를 가장 넓은 선택 상자 또는 텍스트 필드의 크기로하고 싶습니다. 내가 할 수있는 방법이 있니?동적 크기 jqGrid 양식 필드 추가/편집

도움 주셔서 감사합니다.

답변

2

이벤트는 afterShowForm 이벤트를 사용하여 가장 넓은 선택 상자의 너비를 가져오고 모든 선택 항목의 너비를 값으로 설정할 수 있습니다.

표준 편집/

enter image description here

enter image description here

에서 해당 코드 형태를 추가 demo 변화 :

var resizeSelectWidth = function ($form) { 
     var maxWidth = 0, newMaxWidth = 0, i, 
      $selects = $form.find('tr.FormData > td.DataTD > select.FormElement'), 
      cn = $selects.length; 

     // calculate the max width of selects 
     for (i = 0; i < cn; i += 1) { 
      maxWidth = Math.max(maxWidth, $($selects[i]).width()); 
     } 
     maxWidth += 2; // increase width to improve visibility 

     // change the width of selects to the max width 
     for (i = 0; i < cn; i += 1) { 
      $($selects[i]).width(maxWidth); 
      newMaxWidth = Math.max(maxWidth, $($selects[i]).width()); 
     } 
    }; 

... 
$("#list").jqGrid('navGrid', '#pager', {del: true}, 
    {afterShowForm: resizeSelectWidth}, 
    {afterShowForm: resizeSelectWidth});