PDA

View Full Version : [CLOSED] Checkboxmodel : Problem with SelectionModel.getSelection()



matrixwebtech
Dec 25, 2014, 6:38 PM
I try


.SelectionModel(
X.CheckboxSelectionModel()
.ID("s")
.Mode(SelectionMode.Multi)
.Listeners(le =>
{
le.SelectionChange.Handler = "customVisibilityOnOff(this)";

})

)



var customVisibilityOnOff = function (SelectionModel) {

var selected = SelectionModel.getSelection();
console.log(selected.data);


console.log(SelectionModel.getSelection().data);
}
but its show in firebug console is undefined.

Daniil
Dec 26, 2014, 5:55 AM
Hi @matrixwebtech,

The .getSelection() method returns an array of records.
http://docs-origin.sencha.com/extjs/4.2.1/#!/api/Ext.selection.Model-method-getSelection

I think an array has no data property.

By the way, an array of selected records is passed to a SelectionChange listener as an argument.
http://docs-origin.sencha.com/extjs/4.2.1/#!/api/Ext.selection.Model-event-selectionchange

matrixwebtech
Dec 26, 2014, 6:14 AM
Hi,Daniil


The .getSelection() method returns an array of records.
http://docs-origin.sencha.com/extjs/...d-getSelection

I think an array has no data property.

I run my previous code and see in fire bug a data property is present there,so is it possible to get value from data?please see the attached screen shot.
17731

Daniil
Dec 26, 2014, 6:35 AM
I run my previous code and see in fire bug a data property is present there

So, you are inspecting a record. Please clarify how did you open it?


so is it possible to get value from data?

Yes, that is definitely possible.

record.data

matrixwebtech
Dec 26, 2014, 6:49 AM
Please run the sample and inspect in firebug console .

Sample View


@{

var X = Html.X();
}

<script>
var customVisibilityOnOff = function (SelectionModel) {
var selected = SelectionModel.getSelection();
console.log(selected);
console.log(SelectionModel.getSelection());
}
</script>

@X.ResourceManager()
@(X.GridPanel()
.ID("GridPanel1")
.Layout(LayoutType.Anchor)
.ColumnWidth(0.6)
.Store(X.Store()
.ID("Store1")
.DataSource((object)ViewBag.loadgrid)
.Model(X.Model()
.Name("Person")
.IDProperty("id")
.Fields(
Html.X().ModelField().Name("company").Mapping("company"),
Html.X().ModelField().Name("cat").Mapping("cat"),
Html.X().ModelField().Name("price").Mapping("price")
)
)
)
.ColumnModel(
X.Column()
.Text("Company")
.DataIndex("company")
.Flex(1)
.Editor
(
X.TextField()
)
,
X.Column().Text("Category").DataIndex("cat").Flex(1)
,
X.Column()
.Text("price")
.DataIndex("price")
.Flex(1)
.Renderer("Ext.util.Format.euroMoney")

)
.SelectionModel(
X.CheckboxSelectionModel()
.ID("s")
.Mode(SelectionMode.Multi)
.Listeners(le =>
{
le.SelectionChange.Handler = "customVisibilityOnOff(this)";
})
)
)

Sample Controller


public class CheckboxmodelController : Controller
{
//
// GET: /Checkboxmodel/

public ActionResult Index()
{
ViewBag.loadgrid = GetData();
return View();
}

private object[] GetData()
{
var listtest = new List<Checkboxmodelfield>();
for (int i = 1; i <= 4; i++)
{

var v = new Checkboxmodelfield()
{
id = i,
company = "Company " + i.ToString(),
cat = "Cat " + i.ToString(),
price = 10.25
};
listtest.Add(v);
}
return listtest.Cast<object>().ToArray();

}

}
public class Checkboxmodelfield
{
public int id { get; set; }
public string company { get; set; }
public string cat { get; set; }
public double price { get; set; }

}

Daniil
Dec 26, 2014, 8:32 AM
If the selected variable is an array, you should use:

selected[0].data

matrixwebtech
Dec 26, 2014, 8:59 AM
Thanks for correct me.I try
console.log(selected[0].data) and found if I uncheck last checked row then there is an error occurred in java script
TypeError: selected[0] is undefined ,in that case should I check length of selected and if length greater then 0 then only I proceed ?

Daniil
Dec 26, 2014, 9:18 AM
Yes, you can check an array's length or the .hasSelection() method.
http://docs-origin.sencha.com/extjs/4.2.1/#!/api/Ext.selection.Model-method-hasSelection

matrixwebtech
Dec 26, 2014, 10:19 AM
Thanks for confirmation.a question only for my curiosity what is difference between
http://docs-origin.sencha.com/extjs/4.2.1/#!/api/Ext.selection.Model-method-hasSelection
and
http://docs.sencha.com/extjs/4.2.1/#!/api/Ext.selection.Model-method-hasSelection

Daniil
Dec 26, 2014, 10:27 AM
I think there is no difference. It is just two a bit different links to the same.

matrixwebtech
Dec 26, 2014, 10:43 AM
Many Thanks,please close this.