I wanted to change the grid column sequence dynamically. For e.g. By default the grid will be loaded in LoginId, FirstName and LastName sequence. Based on some condition, I need to change the FirstName and LastName sequence.
Is there any way I can do this?
I tried doing like:
{name:'UserName',index:'UserName',width:82,sortable:false},
if(true)
{
{name:'FirstName',index:'FirstName',width:65,sortable:false},
{name:'LastName',index:'LastName',width:65,sortable:false},
}
else
{
{name:'LastName',index:'LastName',width:65,sortable:false},
{name:'FirstName',index:'FirstName',width:65,sortable:false},
}
but I could not get this work.
You can use remapColumns function to do this. In the documentation of the function you will find the example which seems to be wrong, because indexes in the permutation array seem to be 1-based and not 0-based. Try to use:
$("#list").remapColumns([1,3,2],true,false);
or
$("#list").remapColumns([1,3,2,4,5,6,7,8,9],true,false);
if you want to change the order of the second and third from the total 9 columns.
Related
I'd like to know how do you guys get a value from a number field through index search.
I'm using WebForms for my project currently I have this model
[IndexField("SomeNumber")]
int SomeNumber { get; set; }
and obviously a number field named "SomeNumber" in my sitecore item. But the thing is I only get 0 value for SomeNumber when I input a number on the field and a null when not. Note that I'm getting right values for my string fields so I'm not sure why the number field doesn't work right.
Thanks
I have an Order and a Product models.
"Order" HasMany Product (and Product belongsTo Order)...
Let's say I want to display the 3 products of my order, how to do that ?
I know the first could be retrieved like $order->products->first()... but how to retrieve the second and third product?
I tried $order->products->find(1) but "1" represents the id of the product... which I don't want to know...
$order->products()->skip(1)->first();//Second row
$order->products()->skip(2)->first();//Third row
....
Is more performant than loading all products and getting only first, second, ecc..
Instead if you want both second and third, you can get only them in a single query without load other rows, with similar approach:
$order->products()->skip(1)->take(2)->get(); //Skip first, take second and third
I finally found the solution, this is the correct syntax:
$order->products->get(0)->name; will return the first record
$order->products->get(1)->name; will return the second record
$order->products->get(2)->name; will return the third record
And so on...
$order->products()->skip(1)->take(1)->first(); //Second row
$order->products()->skip(2)->take(1)->first(); //Third row
$order->products()->orderBy('salary','desc')->skip(1)->take(1)->first(); //Second highest salary row
$order->products()->orderBy('salary','desc')->skip(2)->take(1)->first(); //Third highest salary row
Say you want a second product from Eloquent Collection
if you are sure that the array keys are same as array indexes, do that
$order->products->get(1)->name;
if you need the second item and you are not sure about the array keys, do this
$order->products->slice(1, 1)->first()->name;
You can simply try this :
$order->products->take(3)->get();
I want to persist the column order via localStorage which is working. However, the column chooser gives the order of the columns based on the current order not the original order.
Example:
3 column table where 0 is first, 1 == second, 2 is last column
0,1,2
choose column order to put last column in first, order becomes
2,0,1
choose column order again and put (original last column) back into last and order becomes:
1,2,0
because it resets the column numbers based on current order rather than ORIGINAL order. How to fix this?
onClickButton: function () {
$(this).jqGrid('columnChooser', {
done : function (perm) {
if (perm) {
localStorage["OD_Table_Col_Order"] = perm;
$(this).jqGrid("remapColumns", perm, true);
}
}
});
}
I think that you can find the solution if you would use remapColumns parameter of jqGrid as additional information.
One more way would be to save in localStorage the array of name properties of colModel items instead of the indexes perm.
I have a DataGrid, created programmatically and loaded from ItemFileReadStore.
I want the first column of DataGrid always be sorted in descending order and disabled for user for sorting. Any other column should be available for sorting as a secondary sortable.
I don't want to give users such a powerful(complex and confusing) feature, as sorting by multiple columns, because there are too many columns in my grid.
So, it should be one sortable column for user and another one "already sorted unsortable" column in fact.
Does anyone know how can this be achieved?
Thanks.
To sort the first column add "sortInfo:-1" when you created your object.
To allow sorting the grid from any other columns but not the first you need to overwrite the function canSort.
To create you grid should now look like this .
dijit.grid.DataGrid({
canSort: function (sortInfo) {
if (Math.abs(sortInfo) == 1){
return false;
} else {
return this.inherited("canSort", arguments);
}
},
sortInfo: -1, .....
If you need to sort on more as one column you need dojox.grid.enhanced.plugins.NestedSorting.
http://dojotoolkit.org/reference-guide/1.7/dojox/grid/EnhancedGrid/plugins/NestedSorting.html
I have a window that looks like so:
Everytime a record is added, I want the repair ID to be set to a unique number that hasn't been used in the table yet. e.g. if there is ID numbers 1,2,3, then when I press +, the ID field should be set to '4'.
Also, if one of the records in the table is deleted, so that the ID numbers are: 1,2,4, then when I press +, the number in the Record ID should be set to 3.
At the moment, I have a custom ManagedObject class, where I declare:
-(void)awakeFromInsert {
[self setValue:[NSDate date] forKey:#"date"];
}
In order to set the date to today's date.
How would I go about implementing this unique record ID?
Thanks!
For a pure autoincrementing ID (like was asked for in this question), something like what's described in this message may do the job. Unfortunately, that won't provide values that fill in the blanks for deleted items in your list.
For small amount of records, simply loop through them until you find a free ID. Pseudocode here since I don't know your language:
int RepairID=1;
While isUsed(RepairID) {
RepairID=RepairID+1;
}
return RepairID;
For large numer of records you can keep track of a list of deleted ID:s and the highest ID. When adding a record pick the smallest deleted ID, or if no deleted ids left to reuse, use the highest ID+1
I've used the numerical form of the date before (with a quick check to make sure it's actually unique - ie, the clock hasn't been adjusted). +[NSDate timeIntervalSinceReferenceDate] returns an NSTimeInterval (which is a typedef double). This I believe is independent of time zones, "daylight saving", etc.
The only weakness, as I alluded earlier, is the clock being adjusted, but you could always make sure it's unique. If you have more requirements than what you listed, let me know. I have a few myself, and what I believe to be sufficient work-arounds.
If your using an Array Controller in your interface you can use the count method on its arrangedObjects array to create your ID. You can implement by overriding your -(id)newObject method
//implemented in yourArrayController.m
-(id)newObject
{
//call the super method to return an object of the entity for the array controller
NSManagedObject* yourNewObject = [super newObject];
//set the ID the count of the arrangedObjects array
NSNumber* theID = [NSNumber numberWithInteger:[[self arrangedObjects] count]];
[yourNewObject setValue:theID forKey:#"ID"];
//return your new Object
return yourNewObject;
}