I want to select items using FlatList like when you select multiple photos on your photo galery (in this case, I am using a flatlist with 2 rows like a grid of 2x10). I want to select (for example) 3 items using onLongPress.
Something like this, but with 2 rows.
What about this:
Every item rendered would have an onLongPress, and an isPicked property.
Initially, and in renderItem(), you would implement an if statement that either renders checked square or empty square every time an item executes executes; To indicate if the item is selected or not (based on isPicked).
onLongPress invokes isPicked and rerenders everything (to toggle the square). So if isPicked is true it becomes false, and if false becomes true. You can achieve that by simply doing this: this.item.isPicked = !this.item.isPicked
Finally on Submit, filter all your initial items (data) by the isPicked === true and hurrah, you will end up with the items that were selected !
Related
After a lot of search in SO without any particular solution, I am compelled to ask this question.
In Simple words - I want to collapse or hide a specific row using Javascript in ag-grid. I have tried several methods explained in ag-grid documentation and also in SO, but none has worked till now.
All the following methods have been tried and none of the codes worked.
Let rowNode = gridOptions.api.getRowNode(params.value);
Method #1. params.api.getDisplayedRowAtIndex(2).setExpanded(false);
Method #2. params.api.getRowNode(params.value).setExpanded(false);
Method #3. gridOptions.api.setRowNodeExpanded(rowNode,false);
Method #4. gridOptions.api.getRowNode(rowId).style.visibility = "collapse";
I have also tried using plain CSS, like this - Data has disappeared but the white blank row is visible
rowNode.setDataValue('class', 'hidden'); //Where “class” is a field
const gridOptions = {
//Other grid options...
getRowClass: params => {
if (params.data.class === "hidden") {
return 'hidden';
}
},
https://stackblitz.com/edit/js-nvtqhz?file=infoCellRenderer.js
setExpand / setRowNode Expanded only works on collapsible rows, i.e it will collapse an expanded row. it will not hide it.
I edited your stackblitz,
I made a couple of changes to make it work.
Selectable Rows
So, when you click a row, I'm marking it as selected. There is a property on ag-grid rowSelection: 'single' | 'multiple. If you want to hide only one row at a time, use 'single' if you can hide multiple rows use 'multiple'
External filtering
So, ag grid can filters rows if we provide a criteria.It can be a check on any of data property as well. For your problem, I have added a filter that says if any row is selected, remove it from the grid.
Following are the changes
/// method called on clicking the button
function hideRow(params) {
let rowNode = gridOptions.api.getRowNode(params.value); // get the clicked row
rowNode.setSelected(true); //mark as selected
gridOptions.api.onFilterChanged(); // trigger filter change
}
Triggering the filter change will call this method for each row
function doesExternalFilterPass(node) {
return !node.selected; // if row node is selected dont show it on grid.
}
You can access the rows hidden any time using
gridOptions.api.getSelectedRows() //Returns an array of data from the selected rows. OR
gridOptions.api.getSelectedNodes() //Returns an array of the selected nodes.
And, if you want to show a row again, just filter from this above mentioned method and do these steps
rowNode.setSelected(false); //mark as unselected
gridOptions.api.onFilterChanged(); // trigger filter change
This will automatically show the row on grid.
Hope this helps! :)
I have added a treeview in my vue component and on the selecting node it should update an array and then show the checkbox as selected. Currently, I am stuck in a situation where I am selecting elements from the tree (which is a folder containing an item) and then going to another folder to select different items. When I am opening the folder I previously selected, it will remove all the selected elements.
Here is my code:
<v-treeview
:items="patchItemsTreeList"
v-model="selectedPatchItemUUIDs"
#input="onChangeOfPatchSelection"
:name="'patchItemsTree'"
:open="openParentNode"
:item-text="'text'"
:key="fold"
:open-all="openParentNode.length === 0"
:selection-type="selectionType"
selectable
open-on-click
dense
#input=onChangeOfPatchSelection
This method is called twice interrupting my logic and deleting my selected items from the array.
Try switching from #input to either #update:active or #update:open. In your case I believe that you need #update:active
<v-treeview
:items="patchItemsTreeList"
v-model="selectedPatchItemUUIDs"
#update:active="onChangeOfPatchSelection"
:name="'patchItemsTree'"
:open="openParentNode"
:item-text="'text'"
:key="fold"
:open-all="openParentNode.length === 0"
:selection-type="selectionType"
selectable
open-on-click
dense
/>
What this will do is instead of emitting the array of selected items, it will emit the open items instead.
If you click this link you can see the code.Problem is when i click on action it is removing redundant data but if i click on another checkbox (i.e family) then it will give the value. but if i put same value as first checkbox (i.e action) then it is showing that value.My aim is if i select two different checkbox it will show only one value
[
{title:'Meet the Robinsons', genre:'action'},
{title:'Meet the Robinsons', genre:'action'},
{title:'MSD', genre:'family'}
]
http://jsfiddle.net/Bw77D/669/
You just need to replace push by splice and remove if (unique):
this.out.splice(0, 1, value);
If I understood right, your problem is when having multiple movies, it only shows the first.
To show all of them you need to remove the condition if (unique) and leave only this.out.push(value);
To show the last item of the list you need to remove the condition if (unique) and replace this.out.push(value); by this.out.splice(0,1,value);
That should fix it.
http://jsfiddle.net/Bw77D/717/
For some reason the rowIDs get reset once i do any any action from the pagination(increase the number of rows,move to next page etc)
for e.g i have 75records in total.Im displaying 15records at a time.In total i have 3 pages each can display 15records.When im in first page which is displaying that records from 1-15 i get rowIDs 1-15 for rows.Now when i move to next page which displays records from 16-30 i get the rowIDs 1-15 for rows.Here when i moved to new page where 16-30 records are being displayed i was expecting the rowIDs to be from 16-30 but they are not,they are from 1-15.Same thing happens when i do an action from pager to display 30 records at a time instead of 15(default).
I want rowID starting from 1 to n number of records instead of 1-15 for each page.Is there a way to do it? If yes than please help me out.thanks
Row Id will work this way because it generates dynamic Ids for your rows when your data is populated in the grid. This is the default behavior.
You can get a unique row Id if you set a Primary key. this way, you'll get the value of Primary key as row Id. Simply set key: true property of the column you want to set as primary key, in the colModel collection.
As you can see in the following screenshot, the SuperBoxSelect component can show multiple selected items on the same line e.g Conneticut and Florida
I would like to change this behavior so that each selection is shown on its own line
try setting stackItems property to true
stackItems When set to true, the items will be stacked 1 per line. Defaults to false which displays the items inline.
stackItems: true