It is possible to retrieve more than 100 list items Sharepoint with ListItemPicker component? - spfx

I'm working with SPFx framework and I'm trying to get all the list items correlated to a specific list. More in details, in my code, I'm using the get() method to retrieve the items, but this function give me only the first 100 elements. This is the piece of code:
async () => {
await this.getConfiguration();
await this.web.lists
.getByTitle(lista_Protocollo)
.get()
.then(async (l) => {
this.setState({ listaProtocolloId: l.Id }),...
Considering I am using the ListItemPicker component, anyone can suggest me a way to overcome the issue?
Thanks
About the mentioned problem, I've know the existence of the getAll() method, but it's not
not suitable in this situation, because I need the Sharepoint list Id. This is an example where I use getAll() method in the solution:
await this.web.lists
.getByTitle(lista_Protocollo)
.items.orderBy("Created")
.getAll()
.then(async (res) => {...

I am not sure why .getAll is not working for you. Anyway, you can also use .top function to overwrite the default limit of 100:
sp.web.lists.getByTitle(lista_Protocollo).items.top(2000).get()
If you want to get both list metadata and list items then you need to make two queries (or a batched query)

Related

Strapi change one collection and apply change to other one

Lets say i create an entry where i can select two collections like this
now , how to detec when someone changed first collection and then apply some filter to data in second collection ?
not sure if you're still looking for the answer but your question ranked high on my search so here's an answer for future visitors.
Say you add a post entry for your Posts collection. In the ./api/post/models/post.js you can create a hook like this
'use strict';
module.exports = {
lifecycles: {
async afterCreate(result, data) {
const id = result.streakID;
const streak = strapi.services.streaks.findOne({ id });
strapi.services.streaks.update({ id }, { counter: streak.counter++ });
},
},
};
My source
Best regards
EDIT: the hook runs on Post creation and accesses the Streak model by way of strapi.services.streaks. To be clear.

Rethinkdb - Not Equal (ne) on multiple fields

I have a document that looks similar to the following
{
...
reactions: [
{
user: 'user_id',
reaction: 'reaction_name'
}, {
user: 'user_id',
reaction: 'reaction_name'
}
]
...
}
I'm trying to remove an item in the array reactions based on a combination of 'user' and 'reaction' which will be unique. How would I go about filtering the reactions array to remove that specific item in rethinkdb using the js driver?
I've tried this
r.db('db_name').table('messages').getAll(
get_single_message
).update({
reactions: r.row('reactions').filter( (item) => {
return item('reaction').ne(body.reaction).and(item('user').ne(body.user))
})
}).run(this._rdbConn)
I understand why it doesn't work (returns all reactions that don't have given reaction, then returns subset of that array that doesn't have certain user).
What I want is for those not equals to be performed in sync so it returns an array that doesn't include items that have the provided reaction AND user. Right now it functions more like reaction OR user.
A buddy helped me out. Here's a solution that works for what I was trying to accomplish, but it does not makes use of not equal. If anyone has another solution that makes use of not equal please share it.
r.db('db_name').table('messages').getAll(
get_single_message
).update({
reactions: r.row('reactions').filter(function (doc) {
return doc('reaction').eq(body.reaction).and(doc('user').eq(body.user)).not()
})
}).run(this._rdbConn)
Here's a possibly more simplified way to do this without .ne:
r.db('db_name').table('messages').getAll(
get_single_message
).update({
reactions: r.row('reactions').difference([{
reaction: body.reaction,
user: body.user
}])
}).run(this._rdbConn)
Just be warned that .difference will remove all instances of that object from the array, so this assumes that there are only single instances of unique combinations of reaction and user.
Or you could keep it closely to what you have already and use the different form of .and()
...
reactions: r.row('reactions').filter( (item) => {
return r.and(item('reaction').ne(body.reaction), item('user').ne(body.user))
})
...

ReactiveUI - ReactiveCommand to get more data for objects in ReactiveList

Currently I am learning ReactiveUI and I am not sure how to approach this problem. What I want to achieve is once a reactive list has been loaded (in this case I am using a command to load it from a local store) I want to be able to trigger that each of the items in the reactive list then go off and fetch data from an api endpoint and update the view model.
What I currently have to load and create the view models using this logic:
LoadSavedLocations = ReactiveCommand.CreateAsyncTask(async o => {
var savedLocations = await _savedLocationService.GetUserSavedLocations();
return savedLocations;
});
LoadSavedLocations.Subscribe(savedLocations =>
{
foreach (var savedZone in savedLocations)
{
Zones.Add(new ZoneDetailViewModel() {
ZoneId = savedZone.ZoneId,
SavedName = savedZone.SavedName,
});
}
});
I want to then be able to have a command that I can kick off (one first load of the screen and then when the user prompts for an update - pull for reload).
There are two ways I think I can do this but struggling with the approach and the code to achieve this.
Option 1
A command which loops through the items in the ReactiveList fetches data from the Api and then updates that viewmodel something along the lines of
UpdateZones = ReactiveCommand.CreateAsyncTask(async o =>
{
foreach (var zone in Zones)
{
// Fetch
// Await
// Update view model
}
return null;
});
With this I am confused around what the return type of the command would be just a new object()? Is there a better way than just looping like this?
Option 2
On the view model ZoneDetailViewModel have a command called FetchExtraData which will then return the data from the API and I can subscribe to that command in the view model and populate the extra properties. With this approach how does the parent viewmodel trigger all the items in the ReactiveList to fire their commands.
For both approaches I don't know how to get each of the items in the ReactiveList to do logic which involves going to an Api and update.

Kendo Ui Grid - fetching only page number of rows on the inital request

I've read several posts here and also the tutorials on Telerik website, but they are lacking - and the documentation is off.
Hoping for a quick fix after hours of reading.
I'm trying to use a Kendo grid with a huge amount of rows (1M). In the examples on the site, I see that the view controller action is returning the whole data set.
Fetching all of the rows is very expensive process and the data set is huge.
My question is how can I configure the grid in such a way that every subsequent callback will return the next page and the initial call will not fetch all of rows at once?
My code is similar to:
//Main controller action
public ActionResult Index()
{
List<items> listItems = GetAllItems(); // very expensive call!
return View(listItems);
}
// my view for that action
#(Html.Kendo().Grid(Model)
.Name("grid")
.Columns(columns =>
{
//some columns...
})
.Pageable(page=>page.PageSizes(true)) //Enable paging - I suspect here I can fix
.DataSource(datasource =>datasource.Ajax().PageSize(20).Read(read => read.Action("MoreItems", "Index")).ServerOperation(true)) // tried all sorts of things here
.Sortable()
.Filterable()
)
// the callbacks for the ajax
public ActionResult MoreItems([DataSourceRequest] DataSourceRequest request)
{
return Json(GetAllItems().ToDataSourceResult(request));
}
//add some cache just to see what was holding the thing up
[OutputCache(Duration = 3600, VaryByParam = "none")]
private static List<items> GetAllItems()
{
//some code to retrieve items
}
(from the examples it looks like the initial call is returning the complete model - and subsequent calls to the Products_Read are on the filter object. How can the initial call be filtered as well but allow for future paging - in my case I have 100k+ rows and it is impossible to do "return View(model") ) Thanks!
Seems that have not been very lucky with Kendo information... What you are looking for is called serverPaging (documentation under framework DataSource in here).
For each request your server will receive:
take contains the number of records to retrieve
skip how many records from the front of the dataset to begin reading
page the index of the current page of data
pageSize the number of records per page
You might also consider using scrollable.virtual (documentation in here where the following pages are loaded while you scroll down in the grid.
This example (http://demos.kendoui.com/web/grid/remote-data.html) uses serverPaging.
It seems that you are not familiar with the LINQ expression engine. The whole collection is never retrieved. The ToDataSourceResult method is doing exactly this - applying paging/sorting/grouping on a database level (thanks to that expression engine).
You do not have to do anything - just pass the IQueryable collection (which holds all the records) to the DataSourceResult, do not call ToList before this(or anything similar) or the magic will be broken :)

Get rid of duplicate entries in autocomplete

I am having difficulty getting rid of duplicate entries which are showing up in autocomplete.
The autocomplete is generated dynamically from a database.
This is the code which is being used for the autocomplete in the control:
public ActionResult AutoCompletefootball()
{
var db = new footEntities();
string selection = this.Request.Params["term"].ToString();
return Json(db.football.Where(a => a.player.Name.StartsWith(selection)).Select(Adds => a.Player.Name), JsonRequestBehavior.AllowGet);
}
All advice welcome
In your return statement (where you use LINQ), add DISTINCT clause.
.Distinct() will eliminate duplicates, but consider that duplicates are appearing because there are many players with the same name, so they are not really duplicate people

Resources