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
close icon

Ignore a column field in the grid editing form

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.

9 Replies

AS Alan Sangeeth S Syncfusion Team November 10, 2015 07:48 AM UTC

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


CA Carlo November 10, 2015 09:27 AM UTC


EditMode.Dialog

  • Product Version you are using?

2015 Vol3 - 13.3.0.7

Thanks a lot for your kind help!





SS Seeni Sakthi Kumar Seeni Raj Syncfusion Team November 11, 2015 11:04 AM UTC

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.


CA Carlo November 11, 2015 02:02 PM UTC

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 =)


GV Gowthami V Syncfusion Team November 12, 2015 05:59 PM UTC

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.



CA Carlo November 13, 2015 08:09 AM UTC

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. 




GV Gowthami V Syncfusion Team November 16, 2015 01:07 PM UTC

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.



CA Carlo December 4, 2015 04:29 PM UTC

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.


AS Alan Sangeeth S Syncfusion Team December 7, 2015 07:17 AM UTC

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

Loader.
Live Chat Icon For mobile
Up arrow icon