How to order table view with numbers 1-2-3 - javafx

I have a table view , and I want to order my rows
for example first row take 1 , the second take 2
I have tried to use
protected static ObservableList<Employee> data = FXCollections.<Employee>observableArrayList();
int i = data.size() + 1;
in my column
But when I delete row ,
and add new row I got bug in order
for example : I have 2 rows , I have delete the first row,
and add new row it should take different order
but I got same number.
I hope you understand my language .

You can call myTableView.sort(); after you added or removed rows. Of course you have to define the sort order first, with a statement like this: myTableView.getSortOrder().add(myColumn);

Related

How to delete DDIC table records which have different id than row number in internal table?

I have an ALV with two rows. I want to delete these rows in internal table and dictionary table also. To get which rows in alv i chose, i use a method
go_selections = go_salv->get_selections( ).
go_rows = go_selections->get_selected_rows( )
Nextly, i am iterating through results LOOP AT go_rows INTO gv_row.
Inside above loop I have an another loop, which stores data from internal table into workarea. Then, i set the counter variable which holds the id of the dictionary table and delete respective row.
LOOP AT gr_data INTO lr_znewfdkey6.
counter2 = lr_znewfdkey6-id.
IF counter2 EQ gv_row.
DELETE FROM znew_fdkey01 WHERE id EQ lr_znewfdkey6-id.
MESSAGE 'Row deleted .' TYPE 'I'.
But unfortunately this works only when id of the dictionary table is equal to row number selected in alv. If I have lr_znewfdkey6-id in dictionary table, equal to for example 5, get_selected_rows( ) returns value started by one etc., and this will cause inequality.
How to fix this?
Get selected rows returns a table of line numbers.
lt_rows = lo_selections->get_selected_rows( ).
Those numbers correspond directly to the itab you loaded into the ALV. No matter if it has been sorted or filtered. It does not correspond to any fields in the database like an ID field or anything.
Assuming gr_datais the itab assigned to the ALV. Let's loop lt_rows and read gr_data at index
LOOP AT lt_rows ASSIGNING FIELD-SYMBOL(<row>).
READ TABLE gr_data INTO ls_data INDEX <row>.
IF sy-subrc = 0.
APPEND ls_data TO lt_selected.
ENDIF.
ENDLOOP.
After executing this will collect selected gr_data lines into lt_selected itab. To delete
LOOP AT lt_selected ASSIGNING FIELD-SYMBOL(<row>).
DELETE TABLE gr_data FROM <row>.
ENDLOOP.
You could also simply do:
LOOP AT lt_rows ASSIGNING FIELD-SYMBOL(<row>).
DELETE gr_data INDEX <row>.
ENDLOOP.
After that refresh your ALV. Should be good.

How can I find out if an update cause a change in SQLITE with Xamarin?

I am using this code;
sql = "UPDATE SCORE SET A = 1 WHERE ID = 12 AND COUNT = 25";
db2.Execute(sql);
Is there a way that I can execute this kind of statement and find out if the update actually found and updated a row?
The execute method returns the number of rows modified. So
var rowsModified = db2.Execute(sql);
if(rowsModified > 0)
{
// the statement found at least one row to update
}
Modified means in this case that a row to update was found. So, it is counted as a modification even when the statement results in assigning the same values already present in the row.

Sorting a datatable by a column that contains part numbers and part letters

I have a datatable and I need to be able to sort either asc or desc by the jobcode column. Unfortunately the column field values contain both numbers and letters like this.
HD1233
HD12333
PG2839
TP9383
I need to extract the numbers, sort numerically and then put it back. So the above would look like this in the output.
HD1233
PG2839
TP9383
HD12333
I have a piece of code which does some sort of sort which is like this ...
Dim dtOut As DataTable = Nothing
dt.DefaultView.Sort = Convert.ToString("jobcode" & Convert.ToString(" ")) & drpAscorDesc.SelectedItem.Text
dtOut = dt.DefaultView.ToTable()
Im just unable to do it properly without the letters. Any advice would be greatly appreciated.
Add another column of type Integer to your DataTable.
Iterate through all DataRows, put values into new column based on job codes in these datarows (read value -> delete all non-numeric characters -> Int32.TryParse()).
Sort by new column.

Edit the code of a GridView column asp.net

I've been looking for a way to control the text that appears in a particular column of a GridView.
For example consider a database with two tables Student and Class.
I want to add a column to the GridView which print out all the students in the Database, the column will show the student's class name, how can do it? (I can normally print the ClassId since its a FK in the student table)
I want to add a column to the GridView which print all the classes, the column will count the number of students in each class, how can I do it?
1- You can do that simply with inner join or a stored procedure to get the class name beside all the data you need in your query.
2- More than one way to do what you want:
For example:
you can add a column to your data table (empty column ), and fill it later through using Sum() aggregate function in a query.
DataTable result_dt = DAL_Helper.Return_DataTable(sqlSelect);//your original query
result_dt.Columns.Add("NumberOfStudent");
result_dt.Columns["NumberOfStudent"].DataType = typeof(string);
result_dt.Columns["NumberOfStudent"].MaxLength = 255;
if (result_dt.Rows.Count > 0)
{
for (int i = 0; i < result_dt.Rows.Count; i++)
{
//Here u can fill your new empty column.
}
}
result_dt.AcceptChanges();
After you return your customized data table(as a data source), you can bind it to the grid view.
Another solution : add an empty column to the grid view and in the RowDataBound event of the grid view you can fill this column through some loop and you can use LINQ to help you in getting the summation.

Column Value of multiselect rows in jqgrid

Its like I have multiselect option in Jqgrid in which i want to pass the selected rows value to the server and based on the value i will delete the rows. I dont want to have the ids to do my work. For the Single row i get the cell value and delete using the same. But for multi select its not the case. In getGridParam('selarrrow'); I use this to fetch the selected rows bu the values are not getting populated. Please help me out in doing the same
When i use the following code as i saw in some sample question i can fetch the value for the single row selection but when i select multiple rows then i pass it says like "FALSE" or "UNDEFINED". What can be the issue. var grid = jQuery('#list'); var sel_id = grid.jqGrid('getGridParam', 'selarrrow'); var myCellData = grid.jqGrid('getCell', sel_id, 'CountryId');
I got this done by using the for loop for getting the selected rows id
i did some thing like this and I am able to fetch the value. Thought this might help others too please check it
var myrow;
var id = jQuery("#List").jqGrid('getGridParam','selarrrow');
if(id.length)
{
for (var i=0;i<id.length;i++) // For Multiple Delete of row
{
myrow = jQuery("#List").jqGrid('getCell',id[i],'ticker');
}
}

Resources