PDA

View Full Version : [CLOSED] Problem with Summary plugins



matrixwebtech
Jul 08, 2014, 7:43 PM
Hi
as per discussion in http://forums.ext.net/showthread.php?38921-Linked-various-fields-In-Grid-example-in-MVC-and-other-functionality post
I design my sample view and almost functionality but need a summary functionality.bellow i describe my view and controller ,where i use a summary column but summary not working.please rectify my code.

VIEW CODE


@model System.Collections.IEnumerable[]
@using Ext.Net
@using Ext.Net.MVC
@{
ViewBag.Title = "ComboBox with Template - Ext.NET MVC Examples";

var X = Html.X();
}


<script>

var addPlant = function () {

var r = Ext.create('pr', {
//common: 'New Plant 1',
//light: 'Mostly Shady',
//price: 0,
//availability: Ext.Date.clearTime(new Date()),
//indoor: false


}),
grid = App.GridPanel1;

grid.store.insert(0, r);
grid.editingPlugin.startEditByPosition({ row: 0, column: 0 });
};

var beforeEdit = function (ed, e) {
var field = this.getEditor(e.record, e.column).field;

switch (e.field) {
case "state":
field.allQuery = e.record.get('country');

break;
case "city":
field.allQuery = e.record.get('state');
break;



}
};

</script>


@X.ResourceManager()
@(X.Store()
.ID("CountryStore")
.Model(X.Model()
.Fields(X.ModelField()
.Name("text")
.ServerMapping("Text")
.Type(ModelFieldType.String)
)
)
.DataSource(Model[0])
)

@(X.Store()
.ID("StateStore")
.Model(X.Model()
.Fields(X.ModelField()
.Name("text")
.Mapping("Text")
.Type(ModelFieldType.String)
)
)
.Proxy(X.AjaxProxy()
.Url(Url.Action("GetStates"))
.Reader(X.JsonReader().Root("data"))
)
)

@(X.Store()
.ID("CityStore")
.Model(X.Model()
.Fields(X.ModelField()
.Name("text")
.Mapping("Text")
.Type(ModelFieldType.String)
)
)
.Proxy(X.AjaxProxy()
.Url(Url.Action("GetCities"))
.Reader(X.JsonReader().Root("data"))
)
)




@(X.GridPanel()
.ID("GridPanel1")
.TopBarItem(X.Button().Text("Add").Listeners(le => { le.Click.Fn = "addPlant"; }).Icon(Icon.Add)
)
.Listeners(l =>
{
l.ViewReady.Fn = "addPlant";
l.ViewReady.Delay = 1;
})
.Frame(true)
.Height(300)
.Width(600)
.Title("Grid")
.ForceFit(true)
.Store(X.Store()
.ID("Store1")
.Model(X.Model()
.Name("pr")
.Fields(
X.ModelField()
.Name("country")
.ServerMapping("Country")
.Type(ModelFieldType.String),

X.ModelField()
.Name("state")
.ServerMapping("State")
.Type(ModelFieldType.String),

X.ModelField()
.Name("city")
.ServerMapping("City")
.Type(ModelFieldType.String),

X.ModelField()
.Name("population")
.ServerMapping("population")
.Type(ModelFieldType.Int),

X.ModelField()
.Name("men")
.ServerMapping("men")
.Type(ModelFieldType.String),

X.ModelField()
.Name("women")
.ServerMapping("women")
.Type(ModelFieldType.String)


)
)

)
.View(
Html.X().GridView().MarkDirty(false)
)

.ColumnModel(
X.Column()
.DataIndex("country")
.Text("Country")
.Editor(X.ComboBox()
.QueryMode(DataLoadMode.Local)
.TriggerAction(TriggerAction.All)
.StoreID("CountryStore")
.ValueField("text")
.DisplayField("text")
),

X.Column()
.DataIndex("state")
.Text("State")
.Editor(X.ComboBox()
.ID("ddlstate")
.QueryMode(DataLoadMode.Remote)
.TriggerAction(TriggerAction.All)
.StoreID("StateStore")
.ValueField("text")
.DisplayField("text")
.CustomConfig(cc => cc.Add(new ConfigItem { Name = "initQuery", Value = "Ext.emptyFn", Mode = ParameterMode.Raw }))
),

X.Column()
.DataIndex("city")
.Text("City")
.Editor(X.ComboBox()
.ID("ddlcity")
.QueryMode(DataLoadMode.Remote)
.TriggerAction(TriggerAction.All)
.StoreID("CityStore")
.ValueField("text")
.DisplayField("text")
.CustomConfig(cc => cc.Add(new ConfigItem { Name = "initQuery", Value = "Ext.emptyFn", Mode = ParameterMode.Raw }))
),

Html.X().SummaryColumn()
.Width(75)
.Text("Population")
.DataIndex("population")
.SummaryType(SummaryType.Sum)
.Renderer("return value ;")
.SummaryRenderer("return value ;")
.Editor(
Html.X().NumberField().AllowBlank(false).MinValue( 0).StyleSpec("text-align:left")
),

X.Column()
.DataIndex("men")
.Text("Men")
.Editor(X.TextField()
.ID("txtMen")

.CustomConfig(cc => cc.Add(new ConfigItem { Name = "initQuery", Value = "Ext.emptyFn", Mode = ParameterMode.Raw }))
)
,
X.Column()
.DataIndex("women")
.Text("Wo-Men")
.Editor(X.TextField()
.ID("txtwomen")

.CustomConfig(cc => cc.Add(new ConfigItem { Name = "initQuery", Value = "Ext.emptyFn", Mode = ParameterMode.Raw }))
)


)
.Plugins(X.CellEditing()
.Listeners(events => {
events.BeforeEdit.Fn = "beforeEdit";
})
.ClicksToEdit(1)
.DirectEvents(events =>
{
events.Edit.Action = "Edit";

events.Edit.EventMask.ShowMask = true;
events.Edit.EventMask.CustomTarget = "App.GridPanel1";
events.Edit.ExtraParams.Add(new Parameter { Name = "field", Value = "e.field", Mode = ParameterMode.Raw });
events.Edit.ExtraParams.Add(new Parameter { Name = "index", Value = "e.rowIdx", Mode = ParameterMode.Raw });
events.Edit.ExtraParams.Add(new Parameter { Name = "recordData", Value = "e.record.data", Mode = ParameterMode.Raw });
})
)


)
@(X.Button().Text("Save").Icon(Icon.DatabaseSave).DirectEvents(d =>
{

d.Click.Action = "save";

d.Click.ExtraParams.Add(new Parameter
{
Name = "values",
Value = "Ext.encode(#{GridPanel1}.getRowsValues())",
Mode = ParameterMode.Raw
});


})
)
CONTROLLER CODE


using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using Ext.Net;
using Ext.Net.MVC;
using System.Text;
namespace ERP_test.Controllers
{
public class masterdetailsController : Controller
{
//
// GET: /masterdetails/

public ActionResult Index()
{
List<object> countries = new List<object>(10);
for (int i = 1; i <= 10; i++)
{
countries.Add(new { Text = "C" + i });
}

return View(new IEnumerable<object>[]
{

countries
});
}

public ActionResult GetStates(string query)
{
List<object> states = new List<object>(10);
if (string.IsNullOrEmpty(query) == false)
{
for (int i = 1; i <= 10; i++)
{
states.Add(new { Text = query + "_S" + i });
}
}

return this.Store(states);
}

public ActionResult GetCities(string query)
{
List<object> cities = new List<object>(10);
if (string.IsNullOrEmpty(query) == false)
{
for (int i = 1; i <= 10; i++)
{
cities.Add(new { Text = query + "_C" + i });
}
}

return this.Store(cities);
}



public ActionResult Edit(string field, string recordData, int index)
{
List<string> fields = new List<string> { "country", "state", "city", "population", "men", "women" };
int startIndex = fields.IndexOf(field);
JsonObject data = JSON.Deserialize<JsonObject>(recordData);
ModelProxy record = X.GetCmp<Store>("Store1").GetAt(index);
Random r = new Random();
switch (field)
{
case "city":
record.Set(fields[3], r.Next(10, 200).ToString());
record.Set(fields[4], r.Next(10, 200).ToString());
record.Set(fields[5], r.Next(10, 200).ToString());
break;
}



return this.Direct();
}

public ActionResult save(string values)
{
string json = values;
Dictionary<string, string>[] companies = JSON.Deserialize<Dictionary<string, string>[]>(json);
StringBuilder sb = new StringBuilder();
foreach (Dictionary<string, string> row in companies)
{
foreach (KeyValuePair<string, string> keyValuePair in row)
{
sb.Append(keyValuePair.Key);
}
foreach (KeyValuePair<string, string> keyValuePair in row)
{
sb.Append(keyValuePair.Value);
}
}
return this.Direct();
}

}
}


please let me know which correction will make the summary working.

Daniil
Jul 09, 2014, 6:05 AM
Hi @matrixwebtech,

Please add this for the GridPanel.

.Features(X.Summary())

matrixwebtech
Jul 09, 2014, 4:14 PM
thanks for reply,it works