Dojo Datagrid Sort after adding New Item to Store - sorting

I'm having an issue with a DataGrid not resorting itself after calling newItem() then save() on the store backing the datagrid.
<div dojoType="dojo.data.ItemFileWriteStore" url="/MultiRaterManagerAjax" id="mrWriteStore" jsId="mrWriteStore"</div>
<table dojoType="dojox.grid.DataGrid" region="left" query="{ hasSub: false }"
clientSort="true" selectionMode="single" jsId="ldrSubGrid" sortInfo="1"
errorMessage="Loading..." store="mrWriteStore">
<thead>
<tr>
<th width="100%" field="_item" formatter="formatSubs">Subs</th>
</tr>
</thead>
</table>
An event handler calls the following javascript
item = mrWriteStore.newItem({});
//set the necessary attributes on item
mrWriteStore.save({onComplete:afterStoreUpdate, onError: saveFailed});
A new item is added to the store, and the DataGrid is updated showing the new item. But the new item is at the bottom of the list. It doesn't seem to recognize the sorting order of the datagrid.
I'm thinking there is an event I need to connect to (or subscribe to) on the datagrid which tells me it has updated the data. Then I call sort/filter functions when this event is fired. But what to connect/subscribe to?

I was struggling with this the other day. I think you need to call the sort() method of the datagrid from inside of your onComplete function, which you have named afterStoreUpdate
dijit.byId('ldrSubGrid').sort();

Related

How to Handle Blazor Wasm Table Input and Changes [duplicate]

How to handle row selected changed event for a table using Blazor?
I tried handling #onchange as well as #onselectionchange.
The syntax for the table looks like this:
<table class="table" #onchange="#this.SelectionChanged">
Your event binding doesn't work because the table element does not emit change events.
Instead, you could add an input element (for example a checkbox) inside your table rows. You can then handle row selection changes by adding your event binding to the input elements.
Read more on the HTMLElement change event in this article.
You can use Onclick in the row:
<tbody>
#foreach (var item in Forecasts)
{
<tr class="#item.Clase" #onclick="#(() => DoSomething(item))">
<td>#item.Date</td>
<td>#item.TemperatureC</td>
<td>#item.TemperatureF</td>
<td>#item.Summary</td>
</tr>
}
</tbody>
and create a Dosomething to receive the item

Knockout Viewmodel binding and Datatable Sorting

I'm using Knockout for data binding and using dataTable+YADCF for Sorting and filtering. My scenario is little complex, on clicking the Category nodes (left side) each time need to make an AJAX call and refresh the table data (right side) through Knockout. This Knockout binding functionality works fine without any issue.
HTML Code
<table class="pdm-data-table pdmList" id="ListCatAttrVal" data-link="row">
<thead>
<tr>
<th>Display Name</th>
<th>Display Source</th>
</tr>
</thead>
<tbody id="listAttribute" data-bind="foreach: attributevalue">
<tr>
<td data-bind="text: dispName"></td>
<td data-bind="text: dispSrc"></td>
</tr>
</table>
Knockout Model Code
if (!ko.dataFor(document.getElementById("listAttribute"))) {
var attributeModel = function () {
this.attributevalue = ko.observableArray();
};
attributeBinding = new attributeModel();
ko.applyBindings(attributeBinding, document.getElementById("listAttribute"));
}
Issue is after applying DataTable for the Table
$("#ListCatAttrVal").dataTable().fnClearTable();
for (var x in response.attributes) {
attributeBinding.attributevalue.push(response.attributes[x]);
}
$("#ListCatAttrVal").dataTable();
After this, Datatable Sorting is not working.
I'm trying to remove the existing generated dataTable and re-initiate it every-time when I click on the category node. But it is not working as expected.
I had a similar issue while working with knockout and datatables - my bindings inside the datatable don't seem to work initially. As a workaround I ended up initialising the datatable in the following way:
var table = $("#ListCatAttrVal").dataTable();
table.fnPageChange(0, true);
After calling fnPageChange (or any other function of datatable library, I believe) bindings seem to be working.

How do I render a partial site to another div?

I want a view with a table on the site and when you click on a table Item, i want to update a partial view with the current object I just clicked on. How do I manage to do this?
<table>
#foreach (var a in annotations)
{
<tr>
<td>
<label onclick="change stuff to new Annotation">#a.Title</label>
</td>
</tr>
}
</table>
<div id="stuff">#Html.RenderPartial("Go", "new annotation")"</div>
You're mixing client-side and server-side code. By the time the click event occurs, you're on the client and server-side code has run and finished.
You could render the partial view in a hidden div and just unhide it on the click event. Something similar to this, perhaps:
<table>
#foreach (var a in annotations)
{
<tr>
<td>
<label>#a.Title</label>
<div style="display:none;">#Html.RenderPartial("Go", a)</div>
</td>
</tr>
}
</table>
<script type="text/javascript">
$(function () {
$('table tr td label').click(function () {
$(this).closest('td').find('div').show();
});
});
</script>
There may be a more elegant way to find the correct div in the jQuery selectors, you can perhaps add classes and ids to DOM elements as needed to make it cleaner. If you have a lot of these table rows then I'd also recommend using the jQuery .on() function for binding the click event as it would perform better. Something like this:
<script type="text/javascript">
$(function () {
$('body').on('click', 'table tr td label', function () {
$(this).closest('td').find('div').show();
});
});
</script>
This would bind a single click event to the DOM instead of many, with the added bonus that dynamically added rows would still handle the event after the binding takes place.
your getting your client side and server side code mixed up here.
#Html.RenderPartial("Go", a)
is a server side method that returns some HTML.
<label onclick=
Is client side code. So by the time your client gets the data it looks like this:
<label onclick="The text returned from html.render partial">
I think you need to read up on MVC a bit more to achieve what you want as your fundamentally going down the wrong route here.

Stripes Checkboxes and Textfields

All -
I'm using stripes to do some form input for a problem I'm working on and I'm stuck on how best to submit a a pair of data using stripes and checkboxes.. for example my page looks like the following:
I have a list of options where users can enable a selection by clicking the box, and also supply some input for that item by entering data into the text field next to it:
<tr>
<td><stripes:checkbox name="item.enable" value="${item.id}"/></td>
<td><stripes:text name="item.value" value="${item.value}"/></td>
</tr>
.....
next item...
When the form is submitted I'd expect my Collection<Item> to be populated yet that's not the case..
How can I best submit a pair of items using the check box fields.
Thanks in advance.
..Chris
Read the documentation on indexed properties. You need to tell Stripes that you have multiple items, by naming them items[0], items[1], etc.:
<tr>
<td><stripes:checkbox name="items[0].enable" value="${item.id}"/></td>
<td><stripes:text name="items[0].value" value="${item.value}"/></td>
</tr>
<tr>
<td><stripes:checkbox name="items[1].enable" value="${item.id}"/></td>
<td><stripes:text name="items[1].value" value="${item.value}"/></td>
</tr>
This supposes that you action bean has a setItems(List<Item> items) method, that the Item class has a public no-arg constructor, and has a setEnable(String itemId) and a setValue(String value) method.
I would wrap this in a JSTL 'forEach' tag and I would put the items in a List. Similar to what JB Nizet said, you also need public setters in the action bean. If you are using Collection<Item> with some implementation other than List<Item> the below snippet won't work.
<c:forEach var='itemIndex' begin='0' end='2'>
<c:set scope='page' var='item' value='${items[itemIndex]}'>
<tr>
<td><stripes:checkbox name="items[${itemIndex}].enable" value="${item.id}"/></td>
<td><stripes:text name="items[${itemIndex}].value" value="${item.value}"/></td>
</tr>
</c:forEach>
There is another case when you don't want the list to default to 3 items. The one I'm thinking of is when the list is already populated. If that is the case I would change the 'end' attribute of the <c:forEach> to be: ${fn:length(actionBean.items) == 0 ? 3 : fn:length(actionBean.items)-1}

Is it possible to return the ActionLink html from a ViewModel? (MVC3 + Razor)

I have a four viewmodels/views which display similar but different data.
Is it possible to have a property on the viewmodel which retuns ActionLinks (or the html for them ?)
e.g.
At the moment on each of my Views I have
<table>
<tr>
<td>#Html.ActionLink("My Open Calls", "MyOpenCalls")</td>
<td>#Html.ActionLink("All Open Calls", "AllOpenCalls")</td>
<td>#Html.ActionLink("My Calls Today", "MyCallsToday")</td>
<td>#ViewBag.Title</td>
</tr>
</table>
but would it be possible to have:
<table>
<tr>
#Model.MenuHtml
</tr>
</table>
While it might be possible to store HTML in view models properties I don't think it would be a good idea. If you want to reuse some code why not simply put this table into a partial and then include the partial:
#Html.Partial("_Links")
Another possibility is to use a custom HTML helper that will generate those links.

Resources