Columns order in ListGrid Smartgwt - smartgwt

How can I programmatically change the order of columns in ListGrid? I have search for an appropriate method in javadoc but found nothing. Is it possible?

Check out setViewState method and this example that saves and restores grid preferences (including column order). So in short, you are interested in getting viewState string from ListGrid data and using it. Remember to redraw grid after setting new viewState.

Related

How to add a non-bound column to a DevExpress DB QuantumGrid

I am using these components:
UniDac for connection to mysql database
DevExpress for QuantumGrid
IDE:
Embarcadero Rad Studio XE2
I have a cxGrid component with one level and a cxGrid1DBTableView specified as the level's View. I can get data from my database and edit it in the grid. I want to add a column that is not in the bound DataSet. When I specify the Column properties value as CheckBox I can see the column but I can't change the value from unchecked to checked by clicking it. The field doesn't have a DataBinding assigned to it. I tried other types of Properties but all are the same I cant change the row value in the grid.
I've been searching for a way to fix this for couple of days, so im hoping you guys can help me.
Are you trying to add a checkbox item that does not have a database field behind it? I have this on one of my forms.
In addition to setting the Properties to "Checkbox" you need to set the DataBinding -> ValueType to "Boolean". The DataBinding->FieldName can be left blank.
To access the values or change their defaults you can use the DataController like this:
View.DataController.Values[i, CheckBoxFieldIndex] := true;
In addition you need to set
DataController.DataModeController.SmartRefresh := true;
To set that option you will also need a KeyField defined for the Controller (DataController.KeyFieldNames)
Setting the SmartRefresh to true will prevent the grid from trying to get an updated value from the underlying dataset. You need to prevent the refresh or the value for the non-bound column will be set back to Null. This comes with some restriction on how you update your dataset. Any changes made to the data in code will not be reflected by the grid unless you explicitly refresh the grid.
You also have to fill the field View.DataController.KeyFieldNames with one of the datasets fields. At least I need it in Delphi 7.

SmartGWT LiveGrid unable to apply style to grid records programmatically

I am using SmartGWT 2.5, specifically a ListGrid backed by a RESTDataSource.
The Server integration is achieved by way of a servlet, and I only need to implement fetchData(). The data is a List<Map<String, Object>> populated on the server side, converted into JSON and sent in the DSResponse. The Live grid backed by the datasource triggers a server fetch programmatically by way of grid.fetchData().
Requirement:
I wish to set a record base style (or custom style) based on the value of one of the record's attributes, which I send over from the server.
In order to do this, I have tried a DataArrivedHandler, where I iterate over the available rows, get the ListGridRecord from the grid using the row number, and use gridRecord.set_baseStyle(String stylename) or gridRecord.setCustomStyle(String stylename) to try and apply a greyed out css for that record. After this, I call grid.markForRedraw(), however to no effect. The CSS does not get applied.
I must mention that I have used the same css to grey out rows on a normal listGrid (no dataSource) very successfully.
Questions:
Is my strategy the right one?
Is there an alternative method to apply a style to a record based on an attribute value.
Your strategy is correct and I have successfully achieved your required functionality in code of mine. Make sure you are correctly getting the record and that the test attribute is present in it. I suggest a JSON.encode(record.getJsObj()) to see what your record actually is filled with. No need for markForRedraw() explicit call, as after the DataArrivedEvent has fired the ListGrid will redraw its view. Post a small code snippet if you need more help. Also as suggested from the comment from Alain, highlights might be another good option to look at.

How do I preserve Telerik MVC grid column order and sizes when paging?

I have a Telerik ASP.NET MVC grid that uses server data binding and has column resizing and reordering enabled. If I manually re-order or re-size the columns and then use the grid pager to jump to another page of the grid, the column sizes and order revert back to the default settings. What is the best way to preserve user changes to the column size and order when paging?
On the Telerik demos site I found an example that uses hidden form fields with AJAX data binding, but as far as I know that won't work for the server binding HTTP GETs. I started down the path of using cookies instead of hidden form fields, but it started getting messy and I was looking for feedback on alternative approaches.
You could pass the column widths down to the grid either as part of your model or with ViewBag (or ViewData if you're using MVC 2)
You can then set your column widths using:
.Width((int)ViewBag.col1Width);
- or -
.Width((int)model.col1Width);
You can then update the values using a callback via the OnColumnResize event (this is raised when a grid column is resized by the user)
If you're using session state, you could also store the values in session variables if they are to persist throughout the user's session.

Delphi: TAdoTable.Insert not really an Insert?

I have two ADO Tables linked as master/details tables, tblCategory (master) and tblItems (details). Both tables have its own grid, and displayed in the same form. I also have data aware controls (dbedits).
Say, currently I'm at: Category=Books, No of Items=10 records, and pointing at record number 5 in the grid. I want to add a new record to the item, so I use:
tblItems.Insert;
The problem is, instead of adding a new row, the grid and the db aware controls are showing the current record (rec No 5). Not inly that, it seems the record is in edit mode too. After I cancel it and repeat the Insert command, only then the new row appeared.
How to fix this, so each time I use tblItems.Insert it always add a new and empty row :)
Nevermind, I think I know what caused it. It's the db aware controls. After the insert command, user will input data. This makes the db aware control receives focus and it automatically sets its position to the current record and displays it.
The solution is to use non-db-aware controls instead, and set the behavior programatically

Add calculated column with checkboxes to datagrid

In my application I have a TcxGrid (devexpress datagrid) that displays the data returned from a stored procedure.
Now I would like to add a column showing checkboxes from which the values cannot come from the database but are calculated internally.
When the checkboxes are clicked, some internal logic needs to be triggered.
Any suggestions?
#boris, I recommend you use the Support Center site of DevExpress for this type of question, there are thousands of articles to DevExpress products.
Anyway I leave here a link to something that might help ;)
How to set up an unbound item in a data-aware View
Are you creating the view at runtime or at designtime?
I sort of cheated when I did this at runtime, and returned a static value as one column from my query:
select false as processed,col1,col2 from table where true
I could then safely attach the dataset, and I had my new column to play with.
You would then perhaps use the properties.onChange or properties.onEditValueChanged for your logic code.

Resources