Data not refreshing when using actionscript to assign dataprovider - flex4

My problem is when I assign the dataprovider for a spark list using actionscript it does not automatically update the list. example:
I have a list:
< s:List id="fiterList" allowMultipleSelection="true" width="100%" height="100%"/>
and I use actionscript to assign the dataprovider:
filterList.dataProvider = model.ADEPTList; (where model.ADEPTList is an ArrayCollection)
When I use an event to update model.ADEPTList the data does not show up in the list.
HOWEVER,
if I instead declare the dataprovider in the MXML like this:
< s:List id="filterList" allowMultipleSelection="true" width="100%" height="100%" dataProvider="{model.ADEPTList}"/>
When the event updates model.ADEPTList it DOES show up in the list. Why is this and how can I get the list to update when assigning the dataprovider using actionscript? Thanks

That's because that's only an assignment, you're not binding your list's dataProvider to model.ADEPTList.
You have to read more about flex binding mechanisms. In AS3 you could use:
BindingUtils.bindProperty(filterList,"dataProvider",model,"ADEPTList");

Related

Referencing elements in RadListView itemtemplate

I'm using RadListView and intercepting onItemLoading event.
Within that event, can I reference individual view elements inside the itemTemplate.
I see args.view._subViews - but I was wondering whether i could find element by name or something else. I assume id would not work because each item would have the same id.
You are correct getting by Id would only return the first one. However, if you have the reference to the ListView child group; using id will work to get the element out of a group.
Now if you use my NativeScript-Dom plugin then it is very simple; you can do:
var elements = RadListView.getElementsByClassName('someClass'); or RadListView.getElementsByTagName('Label'); or the newer functionality `
RadListView.runAgainstTagNames('Label', function(element) {
/* do something with this element */
});
And work with an array of elements that match your criteria.
Please also note that in a ListView that not all elements are preset; ListViews only have as many elements are needed to fill the ListView + 1 typically; so even if you have 2,000 items in the list view; you might only have 10 actual child ListView groups of elements. So when you did a GetElementsByTagNames('Label') you would only get 10 of them...

Kendogrid destroy() and recreate the table on a new datasource, why do the old table columns still exist?

When invoking destroy() in KendoUI Grid and then recreate the table on a new DataSource: why do the old table columns still exist?
The only element here that stays the say is the element. How do I tell the grid to read the new datasource columns (it reads everything else correct).
(if I make 2 different elements, they both populate properly but I rather just keep 1 element and replace the elements table by destroy and reinit)
Most probably this is because you are not clearing the content inside the Grid container. e.g.
$('#gridName').data().kendoGrid.destroy();
$('#gridName').empty();
or shorter syntax
$('#gridName').kendoGrid('destroy').empty();
Other way the Grid takes into account the old html that is left - do not forget that the Grid could be initialized from table like here.
Just want to clarify on the last bit of Peter Subev's answer because it helped me:
"do not forget that the Grid could be initialized from table like here"
This is just saying that in your HTML you used a <table> tag rather than a <div> tag. Using a <table> tag separates the Grid table data from the Grid columns, so when you do $('#gridName').kendoGrid('destroy').empty() it is only destroying/emptying the table data and not the column information.
Switch your HTML <table> tag to a <div> tag to get the desired result.
I'm working in the angular framework and can't seem to reinit the Kendo grid with a new dataSource and new columns. Nothing works on the 2nd grid init. I've tried:
if (vm.mainHierGrid != null) {
//vm.mainHierGrid.data().kendoGrid.destroy();
$('#mainGrid').data().kendoGrid.destroy();
//$('#mainGrid').empty();
vm.mainHierGrid.destroy();
}
Destroy kendo grid and rebind it
if ($('#kgCopyEntityGrid').hasClass("k-grid")) {
$('#kgCopyEntityGrid').kendoGrid('destroy').empty();
}
var kgCopyGrid = $("#kgCopyEntityGrid").kendoGrid({
// your code here
}).data("kendoGrid");

How to click all images on the page at once using Firebug?

I have a page with a lot of images, each of them being wrapped with an onclick event. For example:
<a onclick=javascript:xxx(y,z)><img id="myclass" src="yyy"></a>
Following command returns all the images correctly:
$x("//img")
This doesn't (returns null):
$("img")
I assume, because these img tags were created dynamically, so are not directly in the source.
My idea was to add .click() at the end, but somehow it doesn't work.
So the question is:
How do I simulate clicking all images at once to trigger all associated javascript functions?
You can't .click() on collection as it is just a container for some objects and it doesn't have any methods from objects inside. You need to iterate over each object and call .click() individually:
for (var idx = document.images.length - 1; idx >= 0; idx--){ document.images[idx].click() }
I've just ran it in console and opened your profile and ad on sidebar.

Templating issues with Backbone.js views : this.el attributes

I'm trying to find the best way to render a li-element :
I've read that i should never replace this.el
So it seems that i have to unwrap my template in my LiView render() function :
// replace element content with html generated from template
var $rendered = $.tmpl(this.template, this.model.toJSON());
this.el.html($rendered.unwrap().html());
I just get the contents inside the $rendered li, since i should not replace it.
But how should i transfer attributes ?
I tried :
this.el.attr('class', $rendered.attr('class'));
this.el.attr('title', $rendered.attr('title'));
But it replaces attributes... And some (like jQuery ui ui-draggable) could be lost.
All this seems a bit clunky...
Thanks !
I'm not sure I fully grasp what you're trying to do Olouv, but I'll have a stab at answering your question regardless :)
You have an liView that corresponds to an li dom element
So you need to specify
el: "li"
Do not have an li in your template. Then the result of your render will be
<li>
contents of template
</li>
Now you want to add attributes to this li element?
Class names are pretty simple, just add the className attribute to your view
className: "ui-draggable myGreatClass ui-corner-all"
If you need to add additional attributes to your root (li) element
$(el).attr("title","your title")
If that doesn't work for you, and you want to put the li attributes in your template perhaps consider some form of the following:
Tolerating HTML of the form:
Instead of an liView (list item view), just have a ulView (List view), and put a loop construct in your template

MVC3 WebGrid - Row Id

How can you specify the row id or class with a specific id?
<tr id="row1">
Or even this is ok
<tr class="row1">
I was thinking something like this would work but it doesn't.
#grid.GetHtml(
rowStyle: "row_" + grid.Column(columnName: "Id")
Anyone have any idea how i can possibly use the htmlAttributes or something to get this?
If i was using the for loop then thats easy but the WebGrid allows me to sort and page.
#foreach (var item in Model)
{
var rowid = "row" + #item.Id;
<tr id="#rowid">
checkout this post: http://haacked.com/archive/2011/04/14/a-better-razor-foreach-loop.aspx
eventhough the demonstration is done using FOREACH loop it is very easy to imagine this solution with regular grid control "bound" to model. the thing is that you will calculate this ID as the very last operation before you send the model to view so it works also for sorted grid (so first row has ID = 1).
btw. i really dont get it why this is not supported by grid directly. it is problem also in MVC Contrib grid (ok, this is OSS project so instead of bitching i should implement it :) ). i found such IDs inevitable when you want to make the grid editable because of the way ASP.NET MVC 3 model binder works.

Resources