jTable Conditional show\hide edit and delete buttons based on owner of data

前端 未结 3 2016
清歌不尽
清歌不尽 2021-01-07 03:00

Im using jTable to display CDs info and a child table to show reviews of that CD. I want to be able to only show the edit\\delete buttons on the rows for the user that is lo

相关标签:
3条回答
  • 2021-01-07 03:37

    The following worked for me. It hides the edit/delete button on rows where the current user is not the authorized user. Note: I added a column for authorizedUser in the mysql table and use that to know if the user is allowed or not.

    rowInserted: function(event, data){
         var $currentUser='<?php echo $_SESSION['email']?>';
         if (data.record.authorizedUser != $currentUser) {
            data.row.find('.jtable-edit-command-button').hide();
            data.row.find('.jtable-delete-command-button').hide();
         }
      },
    
    0 讨论(0)
  • 2021-01-07 03:41

    @Toni Your code contains asp.net code too. @ is ASP.NET Directive.

    0 讨论(0)
  • 2021-01-07 03:54
    rowInserted: function (event, data) { 
                                            //After child row loads. Check if the review belongs to the member logged in. If not remove the edit/delete buttons
                                            if (data.record.userID != $user) { 
                                                data.row.find('.jtable-edit-command-button').hide(); 
                                                data.row.find('.jtable-delete-command-button').hide();
                                            }
                                            else{
                                                //If a review record does belong to the user set variable to true so the add new review link can be hidden after all records have been loaded
                                                $memberReviewExists = true;
                                                //Also needed here for when a new record is inserted
                                                $(".jtable-add-record").hide();
                                            }
                                        },
                                        recordsLoaded: function (event, data) {
                                            if (typeof $memberReviewExists != 'undefined' && $memberReviewExists == true){
                                                $(".jtable-add-record").hide();
                                                $memberReviewExists = null;
                                            }
                                            else {
    
        //No review currently exists for this user so show the Add review link                                      $(".jtable-add-record").show();
                                            }
                                        },
                                        recordDeleted: function (event, data) {
    
                                            //User has deleted their review. Re-show the add new review link
                                            $(".jtable-add-record").show();
    
                                        }
    
    0 讨论(0)
提交回复
热议问题