This is a migrated thread and some comments may be shown as answers.

[Solved] Add condition on open grid edit

4 Answers 87 Views
Grid
This is a migrated thread and some comments may be shown as answers.
This question is locked. New answers and comments are not allowed.
Jonisan
Top achievements
Rank 1
Jonisan asked on 29 Mar 2012, 02:54 PM
Hello ,

I have a normal grid with inline edit . Is there an option to allow editing of only the rows created by the login user?
I can have a hidden column in the grid with the creator name , so I can compare it with the user from the session , but where
or how to make this ?

Thankyou

4 Answers, 1 is accepted

Sort by
0
Dadv
Top achievements
Rank 1
answered on 30 Mar 2012, 11:37 AM
This can be achieve in you database request, if you use entities add something like this :

.Where(u=>UserId == Session["UserId"])
0
Jonisan
Top achievements
Rank 1
answered on 30 Mar 2012, 11:55 AM
Hello ,

What I wanted is to allow the user to see all the rows in the grid , but only edit what rows are inserted with he's userID

I added in the model for the grid a Boolean field "allowEdit"  and I added the onRowDataBound event .
Now I can just check if  like this : 

function onRowDataBound(e){       
        if (e.dataItem.qAllowEdit == false) {
   //  setCommandButtonsDisabled
}
}

Now my problem is : How do I make the edit and Delete buttons disable , if my grid has the possibility of reorder of the columns and I cant do something like :  
 var editBtn = e.row.cells[0].children(0).children(0); $//<-----Problem
(editBtn ).addClass("cmd-disabled");
           editBtn.disabled = "disabled";
            $(editBtn).attr('disabled', 'disabled');

 
0
Dadv
Top achievements
Rank 1
answered on 30 Mar 2012, 03:42 PM
<script type="text/javascript">
    function onRowDataBound(e) {
        var dataItem = e.dataItem;
        if (dataItem.qAllowEdit) {
            $(e.row).find('a.t-grid-delete').parent().html('');
   $(e.row).find('a.t-grid-edit').parent().html('');
        }
    }
</script>

.ClientEvents(events => events.OnRowDataBound("onRowDataBound"))    
0
Jonisan
Top achievements
Rank 1
answered on 31 Mar 2012, 10:56 AM
Hello ,

Thank you , exactly what I wanted  ..
I was using the fact that only the cell with the buttons had 2 children , but this is the right way to do it .
Tags
Grid
Asked by
Jonisan
Top achievements
Rank 1
Answers by
Dadv
Top achievements
Rank 1
Jonisan
Top achievements
Rank 1
Share this question
or