Martin S.
Martin S.

Reputation: 256

get the value of an specific cell with jquery bootgrid

I want to use the value of a cell to call another function

i use query.bootgrid and the table loads with the data that i get from the database.

All works fine... data search and sort.. show/hide collmn

In "row 2" the Order_number is "SR14_2254"

<table id="orderGrid" class="table table-condensed table-hover table-striped"  >
<thead>
    <tr>
        <th data-column-id="Id" data-identifier="true" data-visible="false" data-type="numeric" data-width="40">Id</th>
        <th data-column-id="Order_number"  data-width="120" >Auftrag-Nr.</th>
        <th data-column-id="Order_date" data-width="80" >Vom</th>
        <th data-column-id="Status" data-width="60" data-align="right" >Status</th>
        <th data-column-id="Status_since" data-width="80"  >Seit</th>
        <th data-column-id="commands" data-width="200" data-formatter="commands" data-sortable="false">Commands</th>
    </tr>
</thead>
</table>        

<script>
    var orderGrid = $("#orderGrid").bootgrid({
      ajax: true,
      url: "/If/dup/orderTbl.if.dup.php",
      selection: true,
      multiSelect: true,
      ...


    $( document ).ready(function() {
      orderGrid.bootgrid();
      }
</script>

when i click on the a button on the top of the page, the function customerBtn() is called.

i check that only one row is selected for this action.

it works well and when only the second row is selected i get "2",

but i dont get the value of the cell "Order_number" ..

it's allways undefined..

function customerBtn(){
    var rowSelected =$("#orderGrid").bootgrid("getSelectedRows");
        if(rowSelected.length != 1 ){
            alert("sel=" + rowSelected +  "  elements=" + rowSelected.length);  
        }else{
            celValue = $("#orderGrid").data($("#orderGrid").bootgrid("getSelectedRows"));
            console.log(celValue['Order_number'] );
            loadClient(celValue['Order_number']);
        }
    };                              

do anyone has an idea?

Upvotes: 1

Views: 1487

Answers (1)

Martin S.
Martin S.

Reputation: 256

Okay i solved the Problem.

In fact there was 2 errors. the first is that

$("#orderGrid").bootgrid("getSelectedRows");

returns the id assiociated to the data-column-id="Id" field and not to the Row.

var tblData = $("#orderGrid").bootgrid("getCurrentRows");

return the arrays row by row. Then i need just the following code to scan the data :

for(var i=0; i < tblData.length; i++){
    console.log(tblData[i]['Id'] + " => " + tblData[i]['Order_number'] );
    if(tblData[i]['Id'] == rowSelected){
        loadClient(tblData[i]['Order_number']);
        break; 
    }
}  

Now the function loadClient(order) shows well SR14_2254 when i select the second row.

Upvotes: 1

Related Questions