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.
Unfortunately, activation email could not send to your email. Please try again.

Ignore a column field in the grid editing form

Thread ID:

Created:

Updated:

Platform:

Replies:

121074 Nov 9,2015 04:39 AM Dec 7,2015 02:17 AM ASP.NET MVC 9
loading
Tags: Grid
Carlo
Asked On November 9, 2015 04:39 AM

Greetings. In a grid I have the following column declaration:
col.HeaderText("Custom column").TemplateID("#buttonTemplate").Add();
which will contain a button to implement custom logic. The problem with this is that when I edit or insert a row, the grid editing form contains a field named "Custom column". Now, since no data is ever associated to this field, which is there just to contain the button, what should I do in order not to display this field in the grid editing form?
I tried with the following:
col.IsUnbound(true).HeaderText("Sottogruppi").TemplateID("#buttonTemplate").Add();
but this just resulted in the grid not being displayed at all. Thanks for your kind help.

Alan Sangeeth S [Syncfusion]
Replied On November 10, 2015 02:48 AM

Hi Caro,
 
Before we start working on your query, could you please confirm us the following details so that we could provide you a response as early as possible?
 
 
Information provided would be great helpful for us to resolve the issue.
 
Regards,
Alan Sangeeth S

Carlo
Replied On November 10, 2015 04:27 AM


EditMode.Dialog

  • Product Version you are using?

2015 Vol3 - 13.3.0.7

Thanks a lot for your kind help!




Seeni Sakthi Kumar Seeni Raj [Syncfusion]
Replied On November 11, 2015 06:04 AM

Hi Carlo,

We can use Command column and isUnbound propery of Grid to avoid the non-editable field from displayed in the Dialog Edit mode. Please refer to the below code example.

@(Html.EJ().Grid<Object>("FlatGrid")

        .Datasource((IEnumerable<object>)ViewBag.data)

        .AllowPaging()

        .EditSettings(edit => { edit.AllowAdding().AllowDeleting().AllowEditing().EditMode(EditMode.Dialog); })

        .ToolbarSettings(toolbar =>

        {

            toolbar.ShowToolbar().ToolbarItems(items =>

            {

                . . .  .

                items.AddTool(ToolBarItems.Cancel);

            });

        })

        .Columns(col =>

        {

            col.Field("OrderID").HeaderText("Order ID").IsPrimaryKey(true).Add();

             . . . .

            col.HeaderText("Employee Details").Commands(command =>

            {

                command.Type("detail")

                       .ButtonOptions(new Syncfusion.JavaScript.Models.ButtonProperties()

                       {

                           Text = "Details",

                           Width = "100px",

                           Click = "onClick"

                       }).Add();

            })

            .IsUnbound(true)

            .Add();

        })

)

<script>

    function onClick(args) {

        var obj = $("#FlatGrid").ejGrid("instance");

        var OrderID = obj.model.currentViewData[this.element.closest("tr").index()].OrderID ;//Retrieved the clicked(button) record

        alert("OrderID"+OrderID);

    }
</script>



We have prepared a sample with the above solution that can be downloaded from the following location.

Sample: http://www.syncfusion.com/downloads/support/forum/121074/ze/MvcApplication4928870338

Regards,
Seeni Sakthi Kumar S.

Carlo
Replied On November 11, 2015 09:02 AM

Thanks. The proposed solution is working, but I have 2 questions:

1) Isn't there really a better way to get current OrderID (or other properties) than doing the following?

var OrderID = obj.model.currentViewData[this.element.closest("tr").index()].OrderID

this looks a little risky..isn't there a cleaner way to pass these parameters to the function?

2) In future requirements which I'll have to meet, I'll also need to change the button text (at least) and possibly style (like background, foreground) depending, for example, on the value of a model property "IsEnabled" (for instance: if, for the current row, IsEnable = true, then the button should contain the text "Navigate" with a green background. Otherwise, if IsEnable = false, then the button should contain the text "Check" with a red background)

Thanks for the kind help and keep up with this excellent technical support =)

Gowthami V [Syncfusion]
Replied On November 12, 2015 12:59 PM

Hi Carlo,

Before proceeding with your requirement we need below details,

1.       For Query 1, you have mentioned to pass the parameter to the function. Could you please let us know exactly what you have to achieve?


2.       For Query 2, did you need to change the button background and text based on the other field (value of the model property)?


The provided information will help to analyze the issue and we will update you the response as early as possible.

Regards,

Gowthami V.


Carlo
Replied On November 13, 2015 03:09 AM

1.       For Query 1, you have mentioned to pass the parameter to the function. Could you please let us know exactly what you have to achieve?

let's say that my model is as follows:

public class MyModel
{
public Int32 Id {get;set;}
public Int32 ForeignKey1{ get; set; }
public Int32 ForeignKey2{ get; set; }
public bool Condition { get; set; }
}

my requirement is: for each row of the grid which contains the model, a button must be displayed in an unbound column (so that column doesn't appear in the grid editing dialog). Each row button should have a different style (for ex. text and background) based on the value of bool Condition:

  • Then, when I click a row button, if Condition is true (for that row) the button calls an action of a controller passing ForeignKey1 through GET. 
  • If Condition is false (for that row) the button calls an action of a different controller, passing ForeignKey2 through GET. 


2.       For Query 2, did you need to change the button background and text based on the other field (value of the model property)?

Yes, as explained previously the background and text of the button should depend on the "Condition" boolean of the model.


Thanks in advance for your kind help. 



Gowthami V [Syncfusion]
Replied On November 16, 2015 08:07 AM

Hi Carlo,

We have created a custom sample request for your requirement and created a new support incident under your account. Please log on to our support website to check for further updates.

https://www.syncfusion.com/account/login?ReturnUrl=/support/directtrac/incidents

Regards,

Gowthami V.


Carlo
Replied On December 4, 2015 11:29 AM

Thanks for the kind help. I'll sure let you know through direct-trac as soon as I get the chance to try out your solution. Stay tuned.

Alan Sangeeth S [Syncfusion]
Replied On December 7, 2015 02:17 AM

Hi Carlo,

Thanks for the update.

Please follow-up with the incident created under your account for any queries regarding custom sample.

Regards,
Alan Sangeeth S

CONFIRMATION

This post will be permanently deleted. Are you sure you want to continue?

Sorry, An error occured while processing your request. Please try again later.

You are using an outdated version of Internet Explorer that may not display all features of this and other websites. Upgrade to Internet Explorer 8 or newer for a better experience.

;