Pegase745 / sqlalchemy-datatables

SQLAlchemy integration of jQuery DataTables >= 1.10.x (Pyramid and Flask examples)
MIT License
159 stars 67 forks source link

Filter based on another columns value? #45

Closed SeanPollock closed 8 years ago

SeanPollock commented 8 years ago

Hello.

Thanks for the lib! It's very helpful.

Is there a way that I can access another columns value in the filter function? Eg.

columns.append(ColumnDT('cert_type')) columns.append(ColumnDT('cert_num'), filter=some_filter))

So that some_filter, I can change the display depending on cert_type?


def some_filter(cert_num):
     if cert_type == "Authority1":
             return "(Authority 1) " + cert_num
     elif cert_type == "Authority 2":
            return "(Authority 2) " + cert_num
Pegase745 commented 8 years ago

Thanks for the suggestion. I'll try to think of a way to do that

Pegase745 commented 8 years ago

@SeanPollock since 0.3.0 you can.

Define a custom filter function.

def some_filter(cert_row):
     if cert_row.type == "Authority1":
             return "(Authority 1) " + cert_row.num
     elif cert_row.type == "Authority 2":
            return "(Authority 2) " + cert_row.num

And don't forget in your view when declaring your ColumnDT, to use the new filterarg property.

columns.append(ColumnDT('cert_type'))
columns.append(ColumnDT('cert_num'), filter=some_filter, filterarg='row'))
SeanPollock commented 8 years ago

This is awesome, thank you!