Sorting Datastore and Enhanced Datagrid in Dojo - sorting

I need to keep the datastore sorted. When I add sortInfo datastore gets sorted for the first time. When I add another item it goes as last element. Therefore datastore is not in sorted order.
Even if i change the value of the cell in column that needs to be sorted also the order gets disturbed.
How to keep the datastore in dojo be sorted?

You'd need to call a save() on the store to commit your changes for your sort order to be reflected.

Related

Sorting Issue After Table Render in Laravel DataTables as a Service Implementation

I have implemented laravel dataTable as a service.
The initial two columns are actual id and names so, I am able to sort it asc/desc after the table renders.
But the next few columns renders after performing few calculations, i.e. these values are not fetched directly from any column rather it is processed.
I am unable to sort these columns where calculations were performed, and I get this error. And I know it is looking for that particular column for eg outstanding_amount which I don't have in the DB, rather it is a calculated amount from two or more columns that are in some other tables.
Any Suggestions on how to overcome this issue?
It looks like you're trying to sort by values that aren't columns, but calculated values.
So the main issue here is to give Eloquent/MySql the data it needs to provide the sorting.
// You might need to do some joins first
->addSelect(DB::raw('your_calc as outstanding_amount'))
->orderBy('outstanding_amount') // asc can be omitted as this is the default
// Anternative: you don't need the value sorted by
// Don't forget any joins you might need
->orderByRaw('your_calc_for_outstanding_amount ASC')
For SQL functions it'll work as follow
->addSelect(DB::raw('COUNT(products.id) as product_count'));
->orderByRaw(DB::raw('COUNT(products.id)'),'DESC');

Retrieve filtered data from ALV

Is there an easy way of retrieving the ALV data that is displayed when there are also filters used on that ALV?
The ALV used is an object of CL_GUI_ALV_GRID. When showing it to the user, there is a filter placed on it by default. The user also has a button that processes the data in the ALV. How can I make sure the process only works with the data that is displayed, even if the user places his own filters on the ALV?
e.g: An ALV gets created from an itab that has 10 rows, but because there is also a filter passed on the ALV, only 8 rows are showing. When pressing a button, I only want to work with the 8 rows currently showing to the user.
I have tried finding a function module for this purpose but I can only find a FM which works with the selected rows in an ALV.
EDIT: Further, there is a method called get_filtered_entries, but it only retrieves those entries that are NOT displayed. Using this will be quite time-consuming to make the translation to displayed entries. get_filtered_entries
Thanks in advance.
GET_FILTERED_ENTRIES returns a table of excluded row indices. You just have to skip those in your processing.
" Copy original table
DATA(lit_buffer) = it_out[].
" Get excluded rows
o_grid->get_filtered_entries(
IMPORTING
et_filtered_entries = DATA(lit_index)
).
" Reverse order to keep correct indizes; thnx futu
SORT lit_index DESCENDING.
" Remove excluded rows from buffer
LOOP AT lit_index ASSIGNING FIELD-SYMBOL(<index>).
DELETE lit_buffer INDEX <index>.
ENDLOOP.
EDIT: I debugged cl_gui_alv_grid a little and it doesn't seems like that a filtered version of the original table exists at all. The lines get filtered, sorted, grouped and immediately transferred into a table of cells. Looks like it is nearly impossible to get the displayed rows without a performance drawback.

Sorting on hidden data

Is it possible to have data in a Handsontable sorted by a field which is not displayed? I have a grid of data which I would like to display that contains a column called "sortOrder", but I don't want to display this.
The sorting needs to be done client side because events are coming in over web sockets and need to be reflected in the table.
If you're not showing the column then I assume you're not expecting the user to be able to manually sort by this hidden column. Therefore, why don't you simply sort your data array with native JS? At any point during execution you could have a function which sorts by this hidden column and then just don't render this in your Handson definition.
So yes, the answer is it is possible. The not showing of a column is as simple as defining the columns option and not including a column for this hidden value.

Remove all the rows of handson table

I am new to handsontable.
My handsontable rows are readonly.
I wanted to remove all rows of handsontable on a button click.
Please help me.
Do update with empty dataset:
handsontableInstance.updateSettings({
data : []
});
This removes all rows (and leave header if there is some).
There are many ways to "remove" all rows. For example, one, and the easiest, would be to empty your data array. So say that you initialized your HOT instance with the data field as array dataArray. Your button would only need do:
$("#buttonId").click(function() { dataArray = [];})
That would be the easiest way but of course you'd be bypassing HOT. This means that if your application gets more complex and you rely on handlers such as afterRemoveRow, then this method will bypass them. In this latter case, you'd want to use the hot.alter() method as follows:
hot.alter('remove_row', 0); // would remove the row at index 0;
With this I am assuming you know how to use a for loop that could iterate through all rows and remove them, one by one. An expensive operation but it would ensure all the proper handlers get called.
tableInstance.clear()
Clears the data from the table (the table settings remain intact).
refer to the
doc

couchdb - retrieve unique documents for a view that emits non-unique two array keys

I have an map function in a view in CouchDB that emits non-unique two array keys, for documents of type message, e.g.
The first position in the array key is a user_id, the second position represents whether or not the user has read the message.
This works nicely in that I can set include_docs=true and retrieve the actual documents. However, I'm retrieving duplicate documents in that case, as you can see above in the view results. I need to be able to write a view that can be queried to return unique messages that have been read by a given user. Additionally, I need to be able to efficiently paginate the resultset.
notice in the image above that [66, true] is emitted twice for doc id 26a9a271de3aac494d37b17334aaf7f3. As far as I can tell, with the keys in my map function, I cannot reduce in such a way that unique documents will be returned.
the next idea I had was to emit doc._id also in the map function and reduce with group_level=exact the result being:
now I am able to get unique document ids, but I cannot get the documents without doing a second query. And even in the case of a second query, it will require a lot of complexity to do pagination like this (at least I think so).
the last idea I came up with is to emit the entire document rather than the doc._id in the third position in the array key, then I can access the entire document and likely paginate. This seems really brutish.
So my question is:
Is #3 above a terrible idea? Is there something I'm missing? Is there a better approach?
Thanks in advance.
See #WickedGrey's comment to the question. The solution is to ensure that I never emit the same key twice for one document. I do this in the map function by keeping track of the keys as I emit them in an array, then skipping the emit if the key exists in the array.

Resources