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

Question about Grid DataSource

Hi,
I have defined a grid like this:

@(Html.EJ().Grid<ResourceAllocationViewModel>("ResourceAllocated")
                 //.Datasource((IEnumerable<object>)ViewBag.DataSourceTmp)
                               .Datasource(ds => ds.Json((IEnumerable<object>)ViewBag.DataSourceTmp).InsertURL("AddResourceAllocation").UpdateURL("EditResourceAllocation").RemoveURL("DeleteResourceAllocation").Adaptor(AdaptorType.RemoteSaveAdaptor))
                 .EditSettings(es => es.AllowEditing(true))
                                                           .ToolbarSettings(ts => ts.ShowToolbar().ToolbarItems(ti =>
                                       {
                                           ti.AddTool(ToolBarItems.Add);
                                           ti.AddTool(ToolBarItems.Edit);
                                           //ti.AddTool(ToolBarItems.Delete);
                                           ti.AddTool(ToolBarItems.Update);
                                           ti.AddTool(ToolBarItems.Cancel);
                                       }))
 .Columns(col =>
 {
     col.Field("IdResourceAllocation").Visible(false).IsPrimaryKey(true).IsIdentity(true).Add();
     //col.Field("IdResource").Visible(false).IsPrimaryKey(true).Add();
     col.Field("Country").HeaderText("Country").Add();
     col.Field("IdResource").HeaderText("Resource").ForeignKeyField("IdResource")
                                    .ForeignKeyValue("CompleteName").DataSource((IEnumerable<object>)Model.ListaResources)
 
                                    .TextAlign(TextAlign.Left).Add();
     col.Field("FirstName").HeaderText("First Name").Add();
     col.Field("LastName").HeaderText("Last Name").Add();
     col.Field("CanBeAllocated").HeaderText("Allocation").Width(100).Add();
 })
 .ClientSideEvents(cse => cse.BeginEdit("onBeginEditResource"))
 
 )
function onClickResource(args) {
    var curGridElement = this.element.closest("div[id^='child3_grid']");
    var curGrid = $(curGridElement).ejGrid("instance");
    var index = this.element.closest("tr").index();
    var record = curGrid.getCurrentViewData()[index];
 
    var idProject = $("#Project_IdProject").val();
    var objData = { IdProject: idProject, record: record };
    eDialogAllocated.position = { X: this.element.offset().left - 900, Y: this.element.offset().top };
 
    var str = JSON.stringify(record);
    var jqxhr = $.post("@Url.Action("GetResourcesAllocatedCountry""Resources")", objData)
        .done(function(data) {
            //alert(data.success);
            var obj = $("#ResourceAllocated").ejGrid("instance");
            obj.dataSource(data.data);
            onOpenAllocated();
 
        })
        .fail(function(data) {
            alert("error");
        })
        .always(function() {
            //alert("finished");
        });
}

in which I need to reload the Datasource via Javascript.
After that, when I Edit the Record, the Edit Url is not called.
When I refresh the dataSource is it possible that the adaptor is lost?

  Thanks in advance

   Andrea Perazzolo






3 Replies

AP Andrea Perazzolo February 12, 2015 02:13 PM UTC

HI,
I noticed that this problem is in the Patched Service Pack scripts, and is not present in the previous version of the scripts.
When I reverted to the Script you provided me in January 20, the method is called even after the change of DataSource.
This version has another problem which  I asked in another thread, regarding the binding of the DateTime Fields.

    Andrea Perazzolo


AP Andrea Perazzolo February 13, 2015 07:45 AM UTC

I forgot to mention that the Grid is inside a Dialog Control, maybe this is the problem.
Regarding last reply, it was my mistake, the problem there is also with the other patched version of the scripts.


    Hope it helps

    Andrea Perazzolo


PK Prasanna Kumar Viswanathan Syncfusion Team February 13, 2015 10:31 AM UTC

Hi Andrea,

Thanks for using Syncfusion Products.

We have analyzed your sample and found that you have bounded the local data directly with the datasource that affects all URL’s, which is the root cause of the issue. So, we suggest you to use ej.DataManager for binding the data. While binding the data using ej.DataManager, we can include all insert/update and delete URL’s. Then, we have to bind that datamanager with the datasource.

Please find the below code snippet:

$("#button").ejButton({

        click: function (args) {

            $.post("/Grid/Data")

                .done(function (data) {

                    var genData = ej.DataManager({ json: data, updateUrl: "NormalUpdate", insertUrl: "NormalInsert", removeUrl: "NormalDelete", adaptor: "remoteSaveAdaptor" })

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

                    gridObj.dataSource(genData);// Datasource bind to grid

            });

        }

    });

For your convenience we have created a sample and sample can be downloaded from the below link

Sample Link :  http://www.syncfusion.com/downloads/support/directtrac/118221/Sample1182211678771919.zip

Please let us know if you have any queries,

Regards,

Prasanna Kumar N.S.V



Loader.
Live Chat Icon For mobile
Up arrow icon