We use cookies to give you the best experience on our website. If you continue to browse, then you agree to our privacy policy and cookie policy. Image for the cookie policy date

Grid - Custom readonly Row

Hi there,

Is there a way to make a specific row read-only based on a column value i.e. Current user ID. Let's say an employ can see all the orders within the company but only able to edit his/her orders. I am not sure whether this can be achieved through server side.

I am using ASP.NET authentication and can get the user information through HttpContext.User.

Regards
Prasanth

6 Replies

PR Prasanth January 28, 2016 07:54 PM UTC

Hi there,

Adding more to the query:

Also how can a column be made read-only based on another column value e.g. Boolean or DateTime

Regards
Prasanth


PK Prasanna Kumar Viswanathan Syncfusion Team January 29, 2016 11:00 AM UTC

Hi Prasanth,

Thanks for contacting Syncfusion support.

       Queries
                    Response

“Is there a way to make a specific row read-only based on a column value?”

Yes, we can make a specific row read-only by defining args.cancel as true in BeginEdit event of ejGrid. This event triggers before the record is edited. In this event, we get the row details in the arguments. Using for loop, we can get each column value and stop the editing by defining args.cancel as true.

Please find the code example and sample:

@(Html.EJ().Grid<Sample118577.Order>("FlatGrid")

.Datasource(Model)

.AllowSorting()

.AllowPaging()

.EditSettings(edit => { edit.AllowAdding().AllowDeleting().AllowEditing(); })
    .ClientSideEvents(eve => eve.BeginEdit("beginedit").ActionComplete("querycell"))

------------------------------------------------

function beginedit(args) {

        var children = args.row.children();

        for( var i = 0 ; i < children.length ; i++)

        {

            if ($(children[i]).text() == "Brazil")

                args.cancel = true;

        }
    }


Sample: http://www.syncfusion.com/downloads/support/forum/121827/ze/Sample1185771817393863

Refer to the Help document for Beginedit event,

http://help.syncfusion.com/js/api/ejgrid#events:beginedit


“Also how can a column be made read-only based on another column value e.g. Boolean or DateTime”


We can make the column read only using actionComplete event of ejGrid. In this event, we check the condition with the requestType, and disable the CustomerID column by adding the disabled attribute.

Please find the code example and sample:


@(Html.EJ().Grid<Sample118577.Order>("FlatGrid")

.Datasource(Model)

.AllowSorting()

.AllowPaging()

.EditSettings(edit => { edit.AllowAdding().AllowDeleting().AllowEditing(); })
    .ClientSideEvents(eve => eve.BeginEdit("beginedit").ActionComplete("querycell"))

---------------------------------------------------

function querycell(args) {

        if (args.requestType == "beginedit") {

            var data = this.element.find(".e-editedrow").find("input");

            var input = this.element.find(".e-editedrow").find("input")[1];

            for (var i = 0 ; i < data.length ; i++) {

                if ($(data[i]).attr("value") == "false") {

                    $(input).attr("disabled", "disabled");

                }

            }

        }
    }



Refer to the following actionComplete event Help document,

http://help.syncfusion.com/js/api/ejgrid#events:actioncomplete


Regards,
Prasanna Kumar N.S.V



PR Prasanth January 29, 2016 11:04 AM UTC

Hi Prasanna,

Thanks for the prompt reply will try your solution out.  

Also I have just posted another question related same project I am working on.  I know it's Friday but is there any chance of getting back to me before the weekend?  This is the link 
https://www.syncfusion.com/forums/121830/linked-grids-with-batchdatasource

Thanks again for the solution

Regards
Prasanth




PR Prasanth January 29, 2016 01:02 PM UTC

Hi Prasanna,

Ignore my previous request think I have figured it out

Regards
Prasanth


PR Prasanth replied to Prasanthan Thaveenthiran January 29, 2016 01:34 PM UTC

Hi Prasanna,

Ignore my previous request think I have figured it out

Regards
Prasanth

No luck with the new question.. jumped the gun., to avoid confusion will wait for response on other thread .


PK Prasanna Kumar Viswanathan Syncfusion Team February 1, 2016 05:48 AM UTC

Hi Prasanth,

We will update the mentioned thread shortly.


Regards,

Prasanna Kumar N.S.V


Loader.
Up arrow icon