ag-grid sorting on cell value changed - javascript

values in my grid table can change at any time. I would like to keep it sorted after every value change in a sorted column. Is there any grid or column API I can call in onCellValueChanged event?
Regards

You could try something like
gridOptions.api.setSortModel(gridOptions.api.getSortModel())
but this may be overkill - you can also get the state off the current column sort and apply that accordingly

Related

Slickgrid: value entered in a cell disappears after moving out of cell

In a Slickgrid cell, i click and enter a value. Once i move out of this cell using a mouse click the value entered disappears. But if i enter the value in the cell and tab out then the value stays in the cell. I would like to know if this should be manually handled.
OnClick event i am calling
grid.updateRow(grid.getDataItem(args.row));
grid.invalidate();
grid.render();
Thanks,
Asha
You're doing something wrong, updateRow() argument is a row index in the grid but you're passing an item object so that won't work, also if I remember correctly updateRow is only used for re-rendering or refreshing a specific row index, it's not for updating the data but more for rendering purposes (perhaps the naming is confusing).
I personally only use the SlickGrid DataView and the functions to call for updating items are different, you can see how to that in this other Stack Overflow answer Change slickgrid cell data after edit
If you're using the grid object, as it's written in the other SO answer I referenced earlier, then it would be
grid.invalidateRow(args.row);
data[args.row][grid.getColumns()[args.cell].field] = a.msg;
grid.render();
Personally I always use the SlickGrid DataView as it's much more user friendly and comes with a lot more benefit like data grouping and many other functionalities. Again take a look at the other SO answer that I wrote in previous paragraph, that is the correct way to do it

Sort an antd (Ant Design) table that has selection enabled

I am trying to make a table with antd that allows sorting and row selection (using checkboxes).
Right now I have both enabled, however, when I sort by ascending/descending order, the selection does not sort. The checked boxes just stay at the same index as before.
To fix this I tried making a custom sort function that could possibly sort the selectedRowKeys the same way it is sorting the table rows, but I am not able to retrieve the information I need in the callback function to do this.
Has anyone ever done this before?
Any help would be appreciated!
You have not set the key of rows.
You have two ways to do it:
in the objects of the columns array add the key properties (with a property that represents a row identifier)
set rowKey props for the table with the name of the property that represents a row identifier in the columns objects

SlickGrid: sorting after reordering doesn't work

In SlickGrid you can enable row reordering (drag and drop). See http://mleibman.github.io/SlickGrid/examples/example9-row-reordering.html
My problem is that once I reorder a row (e.g. put row 3 above row 1) I can't sort the entries anymore. If a column is named "date" and I click on that column, nothing happens. On the other hand, if I do not reorder the rows manually and then sort by column, it works.
I don't mind that the "sort by column" will destroy my manual order. I just want to keep the option to sort it by column after the reorder.
Any tips are appreciated.
(I am using SlickGrid because there's a nice fork which features sticky rows/columns. I haven't found this feature elsewhere, so it's my only option)
When the grid is manually reordered the function subscribed to moveRowsPlugin.onMoveRows is executed. This function is calling grid.setData(data) to update the reordered rows onto the grid. Calling grid.setData(data) overrides the DataView and directly sets the data on the grid. Updates made to the DataView (e.g. sorting) are therefore no longer reflected on the grid.
To resolve this change grid.setData(data) to dataView.setItems(data) in the function subscribed to moveRowsPlugin.onMoveRows (line 364 of the inline JavaScript). I'd also recommend clearing the sort fields so the sort indicator is removed.
//Set updated data in DataView
dataView.setItems(data);
//Clear sort columns
grid.setSortColumns([]);

jqGrid - Filter rows based on data values

I would like to filter my jqGrid based on certain cell values. For example, if I have a column named "relevance", an integral score from 0 to 10, I'd like to only display rows where relevance > 5. Is this possible to do with jqGrid?
I don't want the user to have to search for values where relevance > 5 – I want the table to load that way from the start.
You need to set filters option of postData to the filter which you need, set search: true option of jqGrid and trigger "reloadGrid". In the answer you will find the corresponding code example.

Column reorder at runtinme

I am using the DataTables plugin for jQuery and I would like to reorder the columns after the data is loaded. I know I can reorder them upon creating the table.
What I would like to do is to draw the table, load the data from the server and then, based on the response from the server, to reorder the columns.
How can I achieve this?
It is possible to do so by using the DataTables plugin ColReorder. After enabling the plugin the columns can be moved with the fnColReorder(from, to) like this:
var table = jQuery("#table_id").dataTable(settings);
table.fnColReorder(4, 10);//move the 4th column on the 10th position
table.fnAdjustColumnSizing();//a good idea to make sure there will be no displaying issues
But there should be payed some attention when using the column indexes: these are the indexes from within the table's columns array. These means, that the index does not have to match the column's number in the table(some columns can be hidden, according to your specification).

Categories