vtfuture / BForms

Bootstrap Forms for ASP.NET MVC
MIT License
62 stars 33 forks source link

Best Way to Jump to a specific Record in a Grid #249

Closed meister-d closed 9 years ago

meister-d commented 9 years ago

Hi Guys Is there a Possibility to Jump to a specific row in the Grid and expand it?

Example : I make a request like this: http://site/Controller/Methot&UserId = 88

Now I want to jump to the User with the Id 88 in my Grid (88 could be for eg also the rowId).

I tried to put some Defaults into the BsGridBaseRepositorySettings but neither QuickSearch, nor UniqueID seemed to work

var gridModel = gridRepository.ToBsGridViewModel(new BsGridBaseRepositorySettings { PageSize = 10 , UniqueID = 88, QuickSearch = "User88"});

Could you provide an example if it's possible...

Regards Dumitru

cristipufu commented 9 years ago

Hi Dumitru,

You need to pass some filters to your repository.

First of all you need a search model:

public class ContributorSearchModel
{
        public int Id { get; set; }
}

Use this model class as the generic parameter of BsGridRepositorySettings

var bsGridSettings = new BsGridRepositorySettings<ContributorSearchModel>()
{
    PageSize = 10,
    Page = 1,
    DetailsAll = true // if you want the row expanded from page load
};

bsGridSettings.Search = new ContributorSearchModel
{
    Id = 88
};

var gridModel = _gridRepository.ToBsGridViewModel(bsGridSettings, x => x.Id);

In your users repository, the one that inheritsBsBaseGridRepository, find the Filter(IQueryable<>) method:

public IQueryable<Contributor> Filter(IQueryable<Contributor> query)
{
    if (Settings.Search != null)
    {
        query = query.Where(x => x.Id == Settings.Search.Id);
    }
}                   
meister-d commented 9 years ago

Hi Cristi, thanx again for your help. This worked for me fine and is exactly what i needed.