On Wed, Sep 29, 2010 at 11:41 PM, hendra kusuma
[email protected]wrote:
it to a grid object, the grid should display what’s in gridtablebase
back then somebody asked the same thing and the conclusion was
But perhaps I am wrong
I end up making a datasource object to handle the situation and
refresh the grid my remaking the gridtablebase object and re-set the grid
table
Thanks
I was wrong. You’re right Alex,
it is possible to update grid with @grid.refresh
I rewrite my gridtablebase object and now it can handle @grid.refresh
here is my code
require ‘rubygems’
require ‘wx’
class Dataset_h < Wx::GridTableBase
def initialize(par={})
super()
if par[:colnames] then @colnames = par[:colnames] else
@colnames
= [] end
if par[:keys] then @keys = par[:keys] else @keys
[] end
if par[:rs] then set_rs(par[:rs]) else @rs =
[] end
@display_data = @rs
@rows = @display_data.size
@cols = @keys.size
end
def get_number_rows
@rows
rescue
0
end
def get_number_cols
@cols
rescue
0
end
def get_value(row, col)
((@display_data[row])[@keys[col].to_sym]).to_s
rescue
""
end
def get_attr(row, col, attr_kind)
Wx::GridCellAttr.new
end
def is_empty_cell(row, col)
true
end
def get_col_label_value(col)
@colnames[col]
rescue
""
end
def set_keys(keys=[])
@keys = keys
end
def set_rs(rs)
@rs = []
rs.each do |key, value|
@rs << value
end
end
def auto_rs(rs)
set_rs(rs)
@display_data = @rs
@keys = rs.keys
@colnames = []
@keys.each do |key|
@colnames << key.gsub('_', ' ').capitalize
end
end
def filter(par)
tmp = []
@rs.each do |row|
par.each do |key, value|
if row[key.to_sym] == value
tmp << row
end
end
end
@display_data = tmp.uniq
@rows = @display_data.size
end
def filter_like(par)
tmp = []
@rs.each do |row|
par.each do |key, value|
if row[key.to_sym].to_s.index(value)
tmp << row
end
end
end
@display_data = tmp.uniq
@rows = @display_data.size
end
def add(data)
@rs << data
end
def delete(row)
@rs[row] = nil
@rs.compact
end
def all
@display_data = @rs
end
def first
@display_data.first
end
def last
@display_data.last
end
end
but then I found another problem
I want this object to be a memory storage, where I can add, update, or
delete and filter rows.
but when I modify data in gridtablebase object, grid is updated, but not
quite perfectly
the grid does not update its row number (and perhaps col number, I have
not
tried that)
so when I filtered, there is empty row below last row
even worse when I add data, if gridtablebase data row counts more than
grid
row
grid will not append rows
is there a way to handle this? since this is so close to what I need,
I really hope there is a way to handle this problem
Thank you