Back

Chess v2.2.0

Because we can!

This is a quite complex example, we won't go much into detail, but it might give an idea of what is possible.

The basic concept is to have the information of each board field (8x8) saved in the database with the value split into color and figure.
e.g. bl|pa means black pawn.

Our Qlik script
Rows:
Load * Inline [
Row
8
7
6
5
4
3
2
1
];

The database consists of 8 columns (aaa,bbb,ccc...), representing the board columns.

Board setup

  • We start by creating a separat Data+ Table to reset the board (or initially filling the database)
    It consists of the row column (1-8) and a button column with bulk edit.
  • We don't display every row but have all 8 loaded with Extended data loading enabled
  • Then we basically hide everything except the button column header.

  • Our rule set for resetting
    Clicking the bulk edit button will simulate a button click in each row, which will trigger our rules. We define the board setup for each row by setting the figure to each column.

    Here the button clicked in row 1 will set the white rook (wh|ro) to column aaa, the white knight (wh|kn) to column bbb and so forth.
    The second row will be filled with pawns (wh|pa).
    The next rows have to be emptied, we dont have to create a rule for each row though, simply use a condition:

    The last two rows for black are handled the same way as white.
    We add a rule to save the data automatically after the bulk edit has been done.
    If we execute the bulk edit now, our database should look like this:

Board

  • For the actual board, we will setup a Data+ Table with the row dimension, 8 button columns (A-H) and 8 text columns (cA-cH) referencing the database columns (aaa-hhh)

    This will already show us our current board information for each field.
  • Setup the alternating field color
  • Overwrite the icon of the button columns We make use of the hasListValue condition for this one:

    and overwrite the button icon with the proper one.
    (here pa means pawn which would be the icon fas fa-chess-pawn)
    We do this for each column (8) for all types of figures (6)
  • We do something similiar to set the color for each column

  • White figures on a white background cannot be seen, so change the background of our 8 button columns to rgb(130,130,130) and set the icon to an empty value (if there is no figure, we don't want to see anything there)

  • We don't need a save button, enable the Save on entry option
  • We are already able to move the pieces around by editing our text fields
  • But we want to click on our buttons of course. Lets create a qlik variable called selected which will hold the information of our currently selected figure
  • Our process will be either
    -> click on a figure
    -> save the field information to the variable
    -> empty the field value (we are removing the figure from the board)
    or
    -> have a figure selected
    -> click on a field
    -> set the selected figure value to the field (overwriting potential existing ones)
  • To work with the selected variable, we will add a measure with its content to the table
  • We can create our click rules now, these have be to be created for each column:
  1. Take a figure from field
    If [A] has a value (there is a figure) and nothing is currently selected

    We will set the value to the selected variable. Our value $(cA)|A$(Row) consists of the content from column [cA] ($(cA)), a Divider (|), the column (A) and the row number ($(Row))
    We empty the field value as well

    We can pick up a figure now
  2. Set figure to field
    If [selected] has a value
    We use a Qlik formula to get our field value left(selected,5) to write to the column

    And reset the selected variable

  3. Highlight the field where we picked up our figure

  • Finally we can give the Table the same design treatment as the Board setup by hiding everything that is not needed and adjusting the row height to have proper squares.

One final feature:

If we duplicate our Data+ Table chess board, we only have to change the [Row] order to have this sweet effect:

Back