2013-12-18 4 views
-1

뷰가 있습니다. 4 개의 열과 여러 행의 테이블이 있습니다. 문자열 값이 있고 마지막 하나에는 button.My가있는 열이 있습니다. 요구 사항은 버튼을 클릭 할 때 First Column 값을 가져와야한다는 것입니다. 내 코드는 다음과 같이 진행됩니다버튼이있는 마지막 열 클릭시 테이블의 첫 번째 열 값 받기

@(Html.Kendo().Grid<Invoice.Models.ViewModels.Setup.AccountViewModel>() 
    .Name("Grid") 
    .Columns(columns => 
    { 
     columns.Bound(p => p.AccountType).Title("Account Type").Width(200); 
     columns.Bound(p => p.AccountName).Title("Account Name").Width(200); 
     columns.Bound(p => p.Currency).Title("Currency").Width(200); 
     columns.Bound(p => p.lkpStatus).Width(225).HtmlAttributes(new { style = "text-align:center" }) 
         .ClientTemplate("# if(data.lkpStatus == 1) " + 
              "{# <span class='label label-success'>Active</span> #} " + 
              "else if(data.lkpStatus ==2) {# <span class='label label-warning'>Blocked</span>#}"+ 
              "else {#<span class='label label-important'>InActive</span># } #").Title("Status"); 

     columns.Command(command => command.Edit()).ClientFooterTemplate("stst").Width(200).Title("Action"); 
    }).ToolBar(toolbar => 
    { 
     toolbar.Template(@<text> 
      <div class="row-fluid"> 
       <div class="span1"> 
        <div class="toolbar" style="height:25px;"> 
         <ul id="menu" style="width:38px; margin-left:22px;" class="span6"> 
          <li style="width:36px;"> 
           <i class="fa fa-plus"></i> 
           <ul> 
            @foreach (var account in @ViewBag.AccountType) 
            { 
             <li style="width:100px;" class="openid"> 
              @if (@account.Value == "Bank") 
              { 
               <label id="Bank1">@account.Value</label> 
              } 
              @if (@account.Value == "CreditCard") 
              { 
               <label id="Credit">@account.Value</label> 
              } 
              @if (@account.Value == "Cash") 
              { 
               <label id="Cash1">@account.Value</label> 
              } 
             </li> 

            } 
           </ul> 
          </li> 
         </ul> 
        </div> 
       </div> 
      </div> 
     </text>); 
    }) 
    .Editable(editable => editable.Mode(GridEditMode.PopUp).TemplateName("UpdateAccount")) 
    .Pageable() 
    .Sortable() 
    .Scrollable() 
    .Filterable() 
    .HtmlAttributes(new { style = "height:550px;" }) 
    .DataSource(dataSource => dataSource 
     .Ajax() 

     //.Events(events => events.Error("error_handler")) 
     .Model(model => model.Id(p => p.AccountID)) 

     .Read(read => read.Action("Account_Read", "Setup")) 
     .Update(update => update.Action("Account_Update", "Setup")) 
    ) 
) <script> 
     $('button').click(function() { 
      $(this).parent().siblings().each(function() { 
       alert('index ' + this.cellIndex + ': ' + $(this).text()); 
      }); 
     }); 
    </script> 
+0

해결책이 필요합니다 .. – SantyEssac

+0

첫 번째 답변이 제공된 후에 질문을 완전히 바꾸지 마십시오. –

답변

1

가장 쉬운 해결책은, siblings():first selctor를 추가합니다.

$('button').click(function() { 
    $(this).parent().siblings(':first').each(function() { 
     alert('index ' + this.cellIndex + ': ' + $(this).text()); 
    }); 
}); 

http://jsfiddle.net/66G3r/

+0

나를 알려주는 "인덱스 정의되지 않음" – SantyEssac

+0

오류를 재현 할 수 없습니다. 0 점을 얻었습니까? –

+0

예 .. 사실 M은 KendoGrid M을 사용해이 질문을 업데이트합니다. – SantyEssac

0
<table> 
    <tr> 
     <th>A</th> 
     <th>B</th> 
     <th>C</th> 
     <th>Action</th> 
    </tr> 
    <tr> 
     <td>Apple</td> 
     <td>Ball</td> 
     <td>Cat</td> 
     <td> 
      <button>Edit</button> 
     </td> 
    </tr> 
    <tr> 
     <td>Apple2</td> 
     <td>Ball2</td> 
     <td>Cat2</td> 
     <td> 
      <button>Edit</button> 
     </td> 
    </tr> 
</table> 


$('button').click(function() { 
    alert($(this).closest("tr").find("td:first-child").text()); 
}); 

http://jsfiddle.net/j6AYu/

0

이 시도 :이 방법에 대해

$('button').click(function() { 
    $(this).closest('tr').find('td').first().each(function() { 
     alert('index ' + this.cellIndex + ': ' + $(this).text()); 
    }); 
}); 
1

를? 그럴 부모의 첫 번째 항목을 얻을 다음 첫 번째 TD 아이를 찾기 위해 .children.first를 사용합니다 .closest() 함수를 사용하여

$('button').click(function() { 
    var first_text = $(this).closest('tr').children('td').first().text(); 
    alert(first_text); 
}); 

.

관련 문제