In rails_admin, how can I filter based on the presence of an association id? - rails-admin

In rails_admin, I've got a list of cities. Some have a numeric state_id and some have a nil. I want my cities list view to let me filter based on whether that field is filled or blank.
How can I do that?
This raises an exception:
config.model 'City' do
list do
filters [:state_id]
...
... because rails_admin can't find "city_id" among its list of "filterable fields", even though it's one of the displayed fields.

You have to set the field as filterable explicitly.
config.model 'City' do
list do
field :state_id do
filterable true
end
With that, I no longer needed the filters setting.

Related

PowerApps compare Table values to Text

I have a collection with job titles and question id's called colFunctions. I want to compare the job titles in the collection to a single known job title (a text value) and return a list of question id's.
So for the function Jr. System Administrator I want to get a list with ID's of Q01 and Q03, but not Q02.
I have this so far, but it says I can't compare a table to a text value. How can I overcome this?
ClearCollect(
colMatchedFunction,
Filter(colFunctions,Function = Office365Users.UserProfileV2(galleryDirectReports.Selected.userPrincipalName).jobTitle).QuestionID
);
If Function is a text column in SharePoint, or a multi-select choice column? If it is a text column, you can use the in operator, which can check if a the text contains the given id:
ClearCollect(
colMatchedFunction,
Filter(
colFunctions,
Office365Users.UserProfileV2(galleryDirectReports.Selected.userPrincipalName).jobTitle).QuestionID in Function
));
In a multi-select choice column, you can still use the in operator, this time to check if a value belongs to a table, checking it against the 'Value' property of the multi-select column (which returns the text value represented by the choice):
ClearCollect(
colMatchedFunction,
Filter(
colFunctions,
Office365Users.UserProfileV2(galleryDirectReports.Selected.UserPrincipalName).jobTitle
in Function.Value
));

Different default sort directions for Columns in Table in React-virtualized

Using the Table and Column components of react-virtualized, I have achieved a default sort column and direction by defining a sortBy dataKey and the sortDirection in the Table component. I have another column, which I would like to have sort in descending order (instead of the default ascending order) the first time a users clicks it, but can't see how to do this. Is it possible to have a default sort direction per Column?
Update: I don't want to sort columns simultaneously, but instead want to have different sort directions for each column when sort is first implemented per column. For example, I want to start the defaults for my table to be sorted by lastname in ascending order. However, I have a few other columns that hold integers or booleans, and that I would like to sort in descending order when the user first clicks on those columns. In ascending order, those columns would first display false and 0's (if any), but would be more meaningful if they were first sorted with true or a set's upper numbers. I'm trying to slightly improve the user experience as to not have to click twice on the columns to get a descending order.
RV's Table does not support the concept of sorting by multiple columns simultaneously. (I'm not sure how it would make sense, unless 1 field is the primary sort and the other is a secondary sort?) Either way, I think that use-case is uncommon.
I think the easiest way to do what you're looking for would be for you to specify your own headerRenderer for the sorted-by Columns:
<Column
{...otherProps}
headerRenderer={yourHeaderRenderer}
/>
You could even decorate the default/built-in header renderer. Then instead of using the sort-by props from Table just pass your own to the sorted-by columns:
import {defaultTableHeaderRenderer} from 'react-virtualized';
function yourHeaderRenderer(props) {
return defaultTableHeaderRenderer({
...props,
sortBy: yourSortByHere,
sortDirection: yourSortDirectionHere
});
}
Update What you're actually asking for here (a default sort direction per column) is completely up to your application. Basically your sort function could look like this:
let prevSortBy;
const sort = ({ sortBy, sortDirection }) => {
if (sortBy !== prevSortBy) {
// You can decide the initial sort direction based on the data.
// Just ignore RV's best-guess default in your case.
}
prevSortBy = sortBy;
// Do your sort-logic here (eg dispatch a Redux action or whatever)
}

Sum specific list items and assign the sum value into a different list

Alright, here's my scenario :
I have 2 custom lists : Orders and Items. The Items list contains a field Description (text) and a Amount Per Item field (calculated). The Orders list contains a Total amount field and a Items field (lookup on the description field in items which allows multiple values selection).
Here's a more visual explanation :
Orders
Total amount
Items (lookup on the description field in items which allows multiple values selection)
Items
Description (text)
Amount per Item
I would like to do the sum of the Amount per Item field of the selected items from the Items lookup field from Orders and put the value of the sum in the total amount field in Orders
Any suggestions? Is it possible to do this in SharePoint 2010 without code? If not, could you show what the code would look like?
Thanks.
You could try
OrderList.Total = OrderList.Items.Sum(item => item.AmountPerItem);

Sharepoint update Lookup Column

I am trying to update a Lookupvalue field "Items" via the SharePoint object model.
"Products" is a column in one list which is used as a lookup column to another list in field "Items".
In my webpart i have dropdown of Items now
string strItems = ddlItems.SelectedValue.ToString();
item["Items"] = new SPFieldLookupValue("strItems");
item.Update();
However, this is causing an error
Internally, SharePoint stores these references like this:
NumericID;#DisplayValue i.e.
145;#Soup
12;#Cake
874;#Steak
That is the kind of thing that should be in the constructor to SPFieldLookupValue. Or if it is more helpful, use the variant of the constructor that takes an int id and string display value.
More info is laid out here:
http://blogs.msdn.com/b/sridhara/archive/2007/08/25/update-quot-lookup-quot-fields-in-sharepoint-2007.aspx
You need to set the Items column to the ID of the SPItem represented by the product. You could do this by setting the DataTextValue of your dropdown to ID and then using the SelectedValue. You could also do a CAML query when a new item is selected in the dropdown.
You can find more information at the bottom of this blog post:
http://weblogs.asp.net/bsimser/archive/2005/05/13/406734.aspx

Complicated condition

I have predefined item combination (for example brand1|brand2|brand3 etc) in the table.
i like to collect brands and check against with predefined table data.
For example i collected brand1|brand2|brand3 then i can do get some value form that predefined table(it meets the condition).
How can i check?
brands would be unlimited. also brand1|brand2|brand3 of brand1|brand2| exist then returns true.
Okay, taking a wild guess at what you're asking, you have a delimited field with brands in them separated by a | character. You want to return any row that has the right combination of the brands in there, but don't want to return rows with, for example, brand "testify" in them when you search for "test".
You have four search conditions (looking for brand3):
the brand exists by itself: "brand3"
the brand starts the delimited field: "brand3|brand4|brand6"
the brand is in the middle of the field: "brand1|brand3|brand6"
the brand is at the end of the field: "brand1|brand2|brand3"
so, in SQL:
SELECT *
FROM MyTable
WHERE BrandField = 'brand3'
OR BrandField LIKE 'brand3|%'
OR BrandField LIKE '%|brand3|%'
OR BrandField LIKE '%|brand3'
Repeat as required for multiple brands.

Resources