EasyUI Forum

General Category => EasyUI for jQuery => Topic started by: pacific202 on October 12, 2011, 10:49:26 AM



Title: Get selected row index in datagrid
Post by: pacific202 on October 12, 2011, 10:49:26 AM
I am trying to update a datagrid using JavaScript, and see that the way to do this is using the updateRow method of the datagrid, which takes two arguments:

Quote
index: the row index to be updated.
row: the new row data.

Is there an easier way to get the selected index in the datagrid?  The only way I can see to do this is by getting the row data using getSelected then passing that data back in to a getRowIndex function.

Is there an example somewhere of how to use updateRow?  This is a complex form and I can't simply use CRUD to update the underlying table.


Title: Re: Get selected row index in datagrid
Post by: pacific202 on October 12, 2011, 10:53:51 AM
Apologies for the misinformation in the above post.  I have updateRow working, but it only takes one argument (of a complex object) and not two.

Here is my function, which updates a datagrid with two fields (Action and Parameters):

Code:
    function tasks_ChangeTask(){

        var selectedrow = $("#tasks-datagrid").datagrid("getSelected");
        var rowIndex = $("#tasks-datagrid").datagrid("getRowIndex", selectedrow);

        var rowData =   {
                            Action : $("#task-dialog-action").combobox("getValue"),
                            Parameters : $("#task-dialog-parameters").val()
                        };


        var param = {
                        index: rowIndex,
                        row: rowData
                    };
        
        $("#tasks-datagrid").datagrid("updateRow", param);
                    
        // close dialog
        $("#task-dialog").dialog("close");

    }

I still want to know how to get the selected row index easily in one step instead of two :)  I might have a datagrid with multiple rows that are exactly the same.