Re: [dabo-users] Sorting in the grid

Author: Paul McNett

Posted: 2009-09-09 at 20:18:51

Ricardo Aráoz wrote:

> Paul McNett wrote:

>> Ricardo Aráoz wrote:

>>

>>> Hello again. I have this grid with 5 columns, works ok but when running

>>> the form if I click on the column headers (to sort it) I get the

>>> following exceptions (one click on every one of the 5 columns, so there

>>> are 5 exceptions). The grid has Sortable=True as do the columns. I just

>>> can't find out what I'm doing wrong.

>>>

>>

>>> File "C:\Python25\lib\site-packages\dabo\dabo\db\dCursorMixin.py",

>>> line 555, i

>>> n __sortRows

>>> self.__unsortedRows.append(row[kf])

>>> KeyError: 'PKId'

>>>

>> You have biz.KeyField set to "PKId". Does that field exist in the table, with that

>> same case-sensitive capitalization? To find out, open a command window from your app

>> (Ctrl+D) and issue:

>>

>> biz = self.getBizobj("<the_bizobj's_datasource>")

>> pkfields = [f[0] for f in self.DataStructure if f[2]]

>> print pkfields

>> print biz.KeyField

>> print biz.KeyField == pkfields[0]

>>

> Second line raised : AttributeError: 'dForm_30698' object has no

> attribute 'DataStructure'

> So I swapped "biz" for "self".

Oops, my bad. :)

> The results were :

> ------------------------------------------------

> []

No pk field found in the DataStructure. What does this give:

print [f[0] for f in self.DataStructure]

Either your pk field isn't being selected as one of the fields, or dabo isn't

identifying the keyfield properly).

> PKId

> Traceback (most recent call last):

> File "<input>", line 1, in <module>

> IndexError: list index out of range

> ------------------------------------------------

> My bizobj :

> class OpMejoraBizobj(dabo.biz.dBizobj):

> def afterInit(self):

> self.DataSource = "OpMejora"

> self.KeyField = "PKId"

> self.addFrom("OpMejora")

> self.addField("Registro")

> self.addField("Revision")

> self.addField("FechaOrigen")

> etc....

Do you have anywhere:

self.addField("PKId")

?

> My table :

> CREATE TABLE opmejora (

> "PKId" INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL,

> "Registro" INTEGER,

> "Revision" INTEGER,

> "FechaOrigen" TEXT,

> "FKSectorOrigen" INTEGER,

> "FKClasificacion" INTEGER,

> etc...

>

> So it would seem ok.

> Though it worries me the fact that I have not defined a DataStructure in

> the bizobj, I thought it was not necessary.

It isn't necessary to explicitly define the DataStructure. Whether you let dabo set

DataStructure automatically, or you set it yourself, DataStructure will be defined.

My practice is to *always* define DataStructure explicitly, because sometimes Dabo's

implicitness causes hard-to-diagnose problems.

Paul

©2009 Paul McNett